Apache + PHP Compilation and Nginx + PHP compilation, the difference:
Apache generally regard PHP as a module of its own to start;
Nginx is the HTTP request variables (such as get,user_agent) forwarded to the PHP independent process, and Nginx communication, known as the fastcgi run mode.
Therefore, PHP compiled for Apache can not be used for Nginx, PHP compiled for Nginx to be in FPM (fastcgi,fastcgi popularly speaking is two programs between the communication) mode of operation.
Enter the directory after PHP decompression:
cd/root/php-5.3.10
Recompile , compile the directory to be separate from the PHP directory already compiled for Apache (can be named fastcgiphp or fastphp)
Configuration :
./configure--prefix=/usr/local/fastphp--with-mysql=mysqlnd--enable-mysqlnd--with-gd--enable-gd-native-ttf-- Enable-gd-jis-conv--ENABLE-FPM
Configuration complete:
Attached: Configuration required options can be found through the./configure-help command, for example
PHP can be run in FPM mode by:
[Email protected] php-5.3.10]#/configure--help|grep php-fpm
[Email protected] php-5.3.10]#./configure--help|grep FPM
PHP and MySQL-related options can be obtained by:
[[email protected] php-5.3.10]#./configure-help|grep MySQL
Mysqlnd is the native driver directory for PHP MySQL.
If you install PHP, you also need to install the GD graphics library:
[Email protected] php-5.3.10]#/configure-help|grep GD
Nginx and PHP integration
In Apache, PHP is a module of Apache, while Nginx and PHP are two equal modules, PHP occupies 9000 ports, when Nginx received a request to run PHP, the request information forwarded to the 9000 port of PHP Process, let the PHP process to process the PHP file under the specified directory , and then return to the Nginx after PHP processing, nginx then return the response to the user. Therefore, in the Nginx configuration, a. php file needs to be forwarded to the PHP process.
"Example" encountered a PHP file, the root directory to the HTML, the request context to the 9000 port of the PHP process, and tell the PHP process the current script is $document _root$fastcgi_scriptname,php will find the script and handle
To edit nginx configuration file vim/usr/local/nginx/conf/nginx.conf:
Add a section of location information
Location ~ \.php$ { root html; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include fastcgi_params; }
$document _root represents the root directory;
$fastcgi _script_name represents the requested file
Smooth restart Nginx.
compiling + installing PHP
[[email protected] php-5.3.10]# make && make install
(Time is longer, if error, make clean in current directory)
The compilation is complete and installed.
Enter the cd/usr/local/fastphp/directory
cd/usr/local/fastphp/
PHP-FPM is the PHP process manager.
Copy the/root/php-5.3.0/lphp.ini (Development environment development) file into the current directory's lib directory:
[Email protected] fastphp]# cp/root/php-5.3.10/php.ini-development ./lib/php.ini
In the ETC directory, the Php-fpm.conf.default copy, named php-fpm.conf:
[email protected] fastphp]# CP etc/php-fpm.conf.default etc/php-fpm.conf
Run SBIN/PHP-FPM:
[Email protected] fastphp]#./sbin/php-fpm
To view the PHP process:
[[Email protected] fastphp]# PS aux|grep php
Test
Vim test.php under/usr/local/nginx/html/:
[Email protected] fastphp]# cd/usr/local/nginx/html/[[email protected] html]# vim test.php
<?php phpinfo ();
Visit: http://192.168.254.100/test.php:
Start MySQL:
Nginx notes and Summary () Nginx and PHP integration