Nginx + Php-fpm + MySQL + Redis source code compilation and installation guide
Note: This tutorial includes the following three parts:
1. Compile and install Nginx in source code
2. Compile and install the source code php and mysql and redis extension modules
3. configure the VM
Download links are provided for the installation package.
Running environment and prerequisites: The g ++ compiling environment has been installed in Ubuntu 12.04 LTS.
The path of all source programs is located in the root @ ubuntu:/home/shihai/Desktop/Nginx folder, as shown in:
The installation path of the program is in the/usr/local folder.
Part 1: install Nginx
Install the dependency Library PCRE, zlib, and SSL libraries before installing Nginx.
Install the PCRE library?? For rewrite
Tar? Zxvf pcre-8.21.tar.gz
Cd pcre-8.21
../Configure -- prefix =/usr/local/pcre-8.21
Make
Make install
Install zlib library?? For gzip compression
Tar? Zxvf zlib-1.2.8.tar.gz
Cd zlib-1.2.8
../Configure -- prefix =/usr/local/zlib-1.2.8
Make
Make install
Install the ssl library?? Supports ssl encryption
Tar-zxvf openssl-1.0.1c.tar.gz
Cd openssl-1.0.1c
./Config -- prefix =/usr/local/openssl-1.0.1
Make
Make install
Install nginx ??Server software
Tar-zxvf nginx-1.2.8.tar.gz
Cd nginx-1.2.8
./Configure -- prefix =/usr/local/nginx-1.2.8 \
-- With-pcre = ../pcre-8.21 /\
-- With-zlib = ../zlib-1.2.8/
Make
Make install
Set the configuration file for nginx startup
/Usr/local/nginx-1.2.8/sbin #./nginx-c/usr/local/nginx-1.2.8/conf/nginx. conf
/Usr/local/nginx-1.2.8/sbin #./nginx-s reload
View nginx processes
Ps? Ef | grep nginx
Open localhost
The Nginx server has been installed successfully.
Part 2: install php and mysql and redis extension modules
Install ncurses?? Prerequisites for installing mysql:
Tar-zxvf ncurses-5.4.tar.gz
Cd ncurses-5.4
./Configure
Make
Make install
Install mysql?? The source code package is used for compilation and installation.
Tar-zxvf mysql-5.1.73.tar.gz
Cd mysql-5.1.73
../Configure -- prefix =/usr/local/mysql-5.1.73
Make
Make install
Install curl Library?? Used for curl requests
Tar-zxvf curl-7.39.0.tar.gz
./Configure -- prefix =/usr/local/curl-7.39.0
Make
Make install
Install php
Tar-zxvf php-5.2.14.tar.gz
Gunzip php-5.2.14-fpm-0.5.14.diff.gz
Patch-d php-5.2.14-p1 <php-5.2.14-fpm-0.5.14.diff
Cd php-5.2.14
./Configure -- prefix =/usr/local/php-5.2.14 \
-- Enable-fastcgi \
-- Enable-fpm \
-- Enable-sockets \
-- Enable-mbstring \
-- With-mysql =/usr/local/mysql-5.1.73 \
-- With-mysqli =/usr/local/mysql-5.1.73/bin/mysql_config \
-- With-pdo-mysql =/usr/local/mysql-5.1.73 \
-- With-curl =/usr/local/curl-7.39.0 \
-- With-openssl =/usr/local/openssl-1.0.1 \
-- With-mcrypt
Make
Make install
Run the following command to start php-fpm:
/Usr/local/php-5.2.14/sbin #./php-fpm start
When you start php-fpm
Startingphp_fpm Dec 29 15:27:32. 502790 [ERROR] fpm_unix_conf_wp (), line 124: pleasespecify user and group other than root, pool 'default'
Solution: go to the directory:/usr/local/php-5.2.14/etc just need to modify the php-fpm.conf
Unix user of processes
Unix group of processes
Set Remove it. Modify the user/group according to the actual situation (www ).
Restart/usr/local/php-5.2.14/sbin #./php-fpm restart successful
Install the redis extension module:
Unzip phpredis-master.zip
ExportPATH =/usr/local/php-5.2.14/bin/: $ PATH
Cp-r phpredis-master php-5.2.14/ext/
Cd php-5.2.14/ext/phpredis-master
Phpize
./Configure -- with-php-config =/usr/local/php-5.2.14/bin/php-config
Make
Make install
Extension Library path:/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/
Under the php Extension Library path, you can find the compiled redis extension library file redis. so.
Open the php. ini file in the path/usr/local/php-5.2.14/lib/php. ini and run the following command:
Vim php. ini
File content Quick Search (press "N" to find the next matching location), run the following command:
:? Extension
Insert the following content after the specified location is found:
Extension = redis. so
Php automatically loads the redis. so file to the extension library path.
If the php. ini file is not found, you can search for the file in full by running the following command:
Find/-name php. ini
The search results show that the/etc/php5/cli/php. ini file exists in this path, so copy to/usr/local/php-5.2.14/lib, run the following command:
/Usr/local/php-5.2.14/lib # cp/etc/php5/cli/php. ini php. ini
Restart php-fpm to take effect. the command is as follows:
/Usr/local/php-5.2.14/sbin #./php-fpmrestart
Part 3: configure the nginx virtual host
Create a virtual host configuration file directory
/Usr/local/nginx-1.2.8 # mkdir vhosts
Cd vhosts
Touch scott.qq.com. conf
Vim scottshi.qq.com. conf
Enter the following content to configure the custom virtual host:
Server {
Listen 8001;/* listening port number */
Server_name scott.qq.com;/* domain name */
Access_log/usr/local/nginxweb/htdocs/access. log;/* site access log */
Location /{
Root/usr/local/nginxweb/htdocs/;/* page file directory */
Index. php index.html index.htm;
}
Error_page 500 502 503 x.html;/* server error page */
Location =/50x.html {
Root html;
}
# Pass the PHP scripts to FastCGI serverlistening on Fig: 9000
Location ~ \. Php $ {
Fastcgi_pass 127.0.0.1: 9000;/* Nginx forwarding request address */
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/usr/local/nginxweb/htdocs/$ fastcgi_script_name;
Include fastcgi_params;
}
Location ~ /\. Ht {
Deny all;
}
}
After saving and exiting, enter the nginx configuration file nginx. conf.
/Usr/local/The nginx-1.2.8/conf # vim nginx. conf
In parallel with the default server level and within the http level, add the following content to make the custom virtual host take effect:
Include/usr/local/nginx-1.2.8/vhosts /*;
After saving and exiting, restart the nginx server and re-load the configuration file. run the following command:
/Usr/local/nginx-1.2.8/sbin #./nginx? S reload
Compile the php test page:
Go to the/usr/local/nginxweb/htdocs/directory, create the test. php file, and enter the content on the test. php page:
Phpinfo ();
?>
Save and exit
Use a browser to access the following address:
Scott.qq.com: 8001/test. php
This page displays the commands for configuring php and various functional modules, including fastcgi, mysql, curl, and redis.