Install and configure php, nginx, and mysql in linux

Source: Internet
Author: User
Tags mcrypt php write

Install and configure php, nginx, and mysql in linux

I am mainly used to install php and interact with nginx and php..Original article: http://www.cnblogs.com/lost-1987/articles/2642979.html

1. Install the plug-in

You can choose YUM installation or source code compilation to install gccgcc-c ++ zlibpcrepcre-devellibeventlibevent-devellibxml2 libxml2-devellibmcrypt libmcrypt-develcurl-devellibpng-devellibtool-ltdl-develgd-developenssl openssl-develncurses-develcmakemysql-devel

 

 

 

2. Install mysql

Tar-zxvf mysql-5.5.25.tar.gz decompress the mysql package and place it in the location where you want mysql to be installed. For example, the/usr/local/webserver/mysql cmake command in this example requires this path cmake \-DCMAKE_INSTALL_PREFIX =/usr/ local/webserver/mysql \-consumer =/user/local/webserver/mysql/data \-DSYSCONFDIR =/etc \-DEXTRA_CHARSETS = all \-DDEFAULT_CHARSET = utf8 \-DDEFAULT_COLLATION = utf8_general_ci \-DWITH_INNOBASE_STORAGE_ENGINE = 1 \-DWITH_ARCHIVE_STORAGE_ENGINE = 1 \-DWITH_BLACKHOLE_STORA GE_ENGINE = 1 \-DWITH_FEDERATED_STORAGE_ENGINE = 1 \-DWITH_PARTITION_STORAGE_ENGINE = 1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE = 1 \-DMYSQL_UNIX_ADDR =/tmp/mysqld. sock \-DMYSQL_TCP_PORT = 3306 \-DWITH_DEBUG = 0 \-DENABLED_LOCAL_INFILE = 1 Press enter to execute, after the execution is complete, continue to execute make & make install # Set Mysql # There are five configuration information files in the support-files directory (this is important here, be sure to copy the corresponding cnf file according to your memory, otherwise mysql will never start): # my-small.cnf (memory <= 64 M) # my-medium.cnf (memory 128 M) # my-large.cnf (memory 512 M) # My-huge.cnf (memory 1G-2G) # my-innodb-heavy-4G.cnf (memory 4 GB) cd/usr/local/webserver/mysqlcp. /support-files/my-huge.cnf/etc/my. cnf vi/etc/my. cnf # Add datadir =/usr/local/webserver/mysql/datawait-timeout = 30max_connections = Connections = MyISAM # modify max_allowed_packet = 16 M/in [mysqld/ /Add mysql running users and user groups groupadd mysqluseradd-g mysql-s/bin/false-d/home/mysql // no shell, Do not log on to the local Machine (for security reasons) cd/usr/local/webserver/mysqlchown-R root. chown-R mysql datachgrp-R mysql. // generate a new mysql authorization table // enter the script directory cd/usr/local/webserver/mysql/scripts // generate a new mysql authorization table using the mysql_install_db script. /mysql_install_db -- basedir =/usr/local/webserver/mysql -- datadir =/usr/local/webserver/mysql/data -- user = mysql // mysql server service item settings in the system // copy the service file and modify cd/usr/local/webserver/mysql/support-filescp mysql. server m Ysqld // modify mysqldbasedir =/usr/local/webserver/mysqldatadir =/usr/local/webserver/mysql/datamv mysqld/etc/init. d/mysqldchmod 755/etc/init. d/mysqld after performing the preceding operations, we can use service mysqld start to start the mysql service. // set the soft connection to enable mysql, mysqldump, the three bin commands of mysqladmin can directly run sudo ln-s/usr/local/webserver/mysql/bin/mysql/usr/binsudo ln-s/usr/local/in shell/ webserver/mysql/bin/mysqldump/usr/binsudo ln-s/usr/local/webserver/mysql/ Bin/mysqladmin/usr/binrm-rf/etc/mysql/my. cnf unable to start mysql because the file has been copied to/etc/my. cnf. /Etc/init. d/mysqld start // set the root password mysqladmin-u root password "admin" // mysql database Chinese garbled solution vi/etc/my. cnf // then add character-set-server = utf8 // under the [mysqld] configuration option and enter the mysqlcd/usr/local/webserver/mysql/binmysql-u root-p prompt enter the password mysql> show variables like '% character % ';

 

3. Install Nginx 

# Tar zxvf nginx-0.8.24.tar.gz # D nginx-0.8.24 #. /configure -- prefix =/usr/local/nginx // here, you only need to specify a path # make & make install #/usr/local/nginx/sbin/nginx // start Nginx and write the service script (do not copy the service script. Write it in linux or press enter to change the line character, causing an exception) vi/etc/init. d/nginx write the following content into the file and save #! /Bin/bash # nginx Startup script for the Nginx HTTP Server # this script create it by gcec at 2009.10.22. # it is v.0.0.1 version. # if you find any errors on this scripts, please contact gcec cyz. # and send mail to support at gcec dot cc. # chkconfig:-85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: ngi Nx # pidfile:/var/run/nginx. pid # config:/usr/local/nginx/conf/nginx. conf nginxd =/usr/local/nginx/sbin/nginx # Set nginx_config =/usr/local/nginx/conf/nginx as the path for installing nginx. conf # Set nginx configuration file location nginx_pid =/var/run/nginx. pid RETVAL = 0 prog = "nginx" # Source function library .. /etc/rc. d/init. d/functions # Source networking configuration .. /etc/sysconfig/network # Check that networking is up. [$ {N ETWORKING} = "no"] & exit 0 [-x $ nginxd] | exit 0 # Start nginx daemons functions. start () {if [-e $ nginx_pid]; then echo "nginx already running .... "exit 1 fi echo-n $" Starting $ prog: "daemon $ nginxd-c $ {nginx_config} RETVAL = $? Echo [$ RETVAL = 0] & touch/var/lock/subsys/nginx return $ RETVAL} # Stop nginx daemons functions. stop () {echo-n $ "Stopping $ prog:" killproc $ nginxd RETVAL =$? Echo [$ RETVAL = 0] & rm-f/var/lock/subsys/nginx/var/run/nginx. pid} # reload nginx service functions. reload () {echo-n $ "Reloading $ prog:" # kill-HUP 'cat $ {nginx_pid} 'killproc $ nginxd-hup retval =$? Echo} # See how we were called. case "$1" in start) start; stop) stop; reload) reload; restart) stop start; status) status $ prog RETVAL = $?; *) Echo $ "Usage: $ prog {start | stop | restart | reload | status | help} "exit 1 esac exit $ RETVAL save and grant the File Permission chmod 755/etc/init. d/nginx we can start the service through service nginx start.

 

4. install php

create user and group for fpm(fastcgi process manager)groupadd fpmuseradd --shell /sbin/nologin -g fpm fpmdownload, configure and install php5.3.3wget http://www.php.net/distributions/php-5.3.3.tar.gztar zxvf php-5.3.3.tar.gzcd php-5.3.3
[Copy directly]. /configure -- prefix =/usr/local/php -- enable-fpm -- with-fpm-user = fpm -- with-fpm-group = fpm -- with-config-file-path = /usr/local/php/lib -- with-mysql = mysqlnd -- with-mysqli = mysqlnd -- with-pdo-mysql = mysqlnd -- without-pdo-sqlite -- without-sqlite3 -- without-sqlite -- with-curl -- enable-mbstring -- with-mhash -- with-mcrypt -- with-openssl -- with-gd -- enable-sockets -- with-gettext -- with-zlib -- enable-zip -- enable-soap -- with-xmlrpc -- with-freetype-dir =/usr/local/freetype -- enable-gd-native-ttf
--disable-fileinfo
For errors in the middle, you need to install several dependent packages in yum install [manual version]. /configure -- prefix =/usr/local/php \ -- enable-fpm \ -- with-fpm-user = fpm \ -- with-fpm-group = fpm \ -- with-config- file-path =/usr/local/php/lib # configure php. storage location of ini -- with-mysql = mysqlnd \ -- with-mysqli = mysqlnd \ -- with-pdo-mysql = mysqlnd \ -- without-pdo-sqlite \ -- without-sqlite3 \ --- sqlite \ -- with-mysql-sock =/tmp/mysql. sock \ -- with-curl \ -- enable-mbstring \ -- with-mhash \ -- with-mcrypt \ -- with-openssl \ -- with-gd \ -- enable-sockets \ --- gettext \ -- with-zlib \ -- enable-zip \ -- enable-soap \ -- with-xmlrpc \ -- with-freetype-dir =/usr/local/freetype \ -- enable-gd -native-ttf \ -- with-jpeg-dir =/usr/lib64 #64-bit lib64 32-bit lib32 make & make install make error virtual memory exhausted: cannot allocate memory, add-disable-fileinfo to configure
If an error occurs in mysql_config not found, solution: Add export PATH = "$ PATH: /usr/local/mysql/bin "is the directory where your mysql is installed.


 

5. Configure php

Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf copy source package php. ini-development to/usr/local/php/libvi php-fpm.conf find "listen =" change to listen =/dev/shm/php-fpm.sock (require php version 5.3 or above this method to use sock files listener) cp/backups/php-5.3.3/php. ini-development/usr/local/php/lib/php. start php/usr/local/php/sbin/php-fpm in iniIf the path is set correctly, php. the INI file also exists and php cannot be loaded. modify the startup command/usr/local/php/sbin/php-fpm-c/etc/php. iniWrite a service script (do not copy the service script. Please write it in linux or press ENTER or the line break will cause an exception) touch/etc/init. d/phpfpmvim/etc/init. d/phpfpm content is as follows:

#! /Bin/bash

Start (){

/Usr/local/php/sbin/php-fpm

/Bin/echo 'starting php listener --- [OK]'

}

Stop (){

/Usr/bin/pkill php-fpm

/Bin/echo 'stopping php listener --- [OK]'

}

Case "$1" in

Start)

Start

;;

Stop)

Stop

;;

Restart)

Stop

Start

;;

*)

Echo 'usage: start/stop/restart'

Exit 0

;;

Esac

 

Save and exit

Then you can start the listener through service phpfpm start/stop/restart.

6. Configure Nginx

Cat/usr/local/php/etc/php-fpm.conf view port 127.0.0.1: 9000 modify nginx configuration file/usr/local/nginx/conf/nginx. conf # location/{// note this part. Otherwise, the PHP file will be downloaded instead of being parsed. # root html; # index index.html index.htm ;#}
Location ~ \. Php {root www; # This is the root directory of your website, fastcgi_pass 127.0.0.1: 9000; # The port for listening to the fastcgi process is specified here, And nginx interacts with php # fastcgi_pass unix: /dev/shm/php-fpm.sock;
Fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME $ document_root/$ fastcgi_script_name; # Because SCRIPT_FILENAME is written dead in the configuration, it does not change with $ doucument_root, we can modify the SCRIPT_FILENAME configuration as follows # fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include fastcgi_params ;} restart the nginx service/usr/local/nginx/sbin/nginx-s reload and create the www directory mkdir www under/usr/local/nginx to create an index. PHP file cd wwwvim index. php write <? Php echo phpinfo ();?> If the access server works, the configuration is successful.

 

7. Set php nginx mysql to start automatically

I want to disable the graphic interface in centos. Select the recommended system running level 2 or 3. Check/etc/init before configuring. d. Are there any mysql, php, and nginx service scripts? If not, configure the following operations first, for example, mysqld, nginx, phpfpm scripts are compiled and put into/etc/init. d. Let's Configure Automatic startup. I want to use a service to start these three services. Then I can write another script.

Note: All system services can be started using the service, and chkconfig can be used to add and del

However, when you use chkconfig to configure some services configured by yourself, the system prompts "service XX does not support chkconfig"

This is generally caused by a script that does not conform to the format. The solution is as follows,

Add two lines of content to the script:

# Chkconfig:-85 15

# Description: this is a World Wide Web server.

Mv/etc/init. d/mysqld/etc/init. d/webapp-mysqldmv/etc/init. d/nginx/etc/init. d/webapp-nginxmv/etc/init. d/phpfpm/etc/init. d/webapp-phpfpmtouch/etc/init. d/webappvim/etc/init. d/webapp write the following script

#! /Bin/bash

# Chkconfig:-85 15
# Description: this is a World Wide Web server.

ACTION = $1

If ["$ ACTION" = ""] | ["$ ACTION" = "start"]; then

# Start php listeners

/Sbin/service webapp-phpfpm start

# Start nginx service

/Sbin/service webapp-nginx start

# Start mysql service

/Sbin/service webapp-mysqld start

Echo "web applications [mysql, nginx, php] is running now! "

Elif ["$ ACTION" = "stop"]; then

/Sbin/service webapp-phpfpm stop

/Sbin/service webapp-nginx stop

/Sbin/service webapp-mysqld stop

Echo 'web application stopped'

Else

Echo "use start or stop or none after your service command"

Fi

 

 

Add System Service Startup

Chkconfig -- add webapp (note that the Service script under/etc/init. d must add the content of # chkconfig and # description to support the chkconfig command here, as mentioned above)

Chkconfig -- level 3 webapp on

 

In this way, our lamp architecture is successfully configured.

 

Note:

Syntax: chkconfig -- list [name] is used to list the service chkconfig -- add name is used to add the service chkconfig -- del name is used to delete the service chkconfig [-- level levels] name changes the startup information and checks the startup status of a specific service. On and off indicate the start and stop of the service when the running level is changed. Reset refers to initializing service information. For on and off switches, the system is only valid for 3, 4, and 5 by default, but the reset can be valid for all running levels.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.