FastCGI working method:
FastCGI works by separating the PHP service and using a process to run php, instead of loading PHP through the Apache module, so that PHP will work in the memory. when responding to the Apache server, by enabling the thread, the execution efficiency is greatly improved and memory usage is saved.
(1) We can use the FastCGI module of Apache to construct Apache + PHP.
1. Download mod_fastcgi-2.4.6.tar and decompress
Tar xf mod_fastcgi-2.4.6.tar
2) copy the makefile. AP2 file, rename it to makefile, and change the value of top_dir to the installation path of the Apache server on the system.
# Cd mod_fastcgi-2.4.6
# Vim makefile
Top_dir =/usr/local/Apache
3) install mod_fastcgi and edit httpd. conf to add the loading statement so that httpd can be loaded to the FastCGI module. Then restart the HTTPd service.
# Make install
# Vim/etc/httpd. conf
Loadmodule fastcgi_module modules/mod_fastcgi.so
If you have already installed PHP, You Need To comment out the following line.
# Loadmodule php5_module modules/libphp5.so
(2) Compile and install PHP
1) decompress the source code package and configure the compilation options.
# Tar xf php-5.3.6.tar.bz2
# Cd php-5.3.6
#. /Configure -- prefix =/usr/local/PhP5 -- With-mysql =/usr/local/MySQL -- enable-FPM -- With-mstrap -- With-mbstring -- With-Gd -- sysconfdir =/etc/PHP -- With-mysqlli =/usr/local/MySQL/bin/mysql_config
# Make
# Make install
2) copy the PHP configuration file and the PHP-FPM configuration file to the correct location.
# Cp PHP. ini-production/usr/local/PhP5/lib/PHP. ini
# Cp/etc/PHP/php-fpm.conf.default/etc/PHP/php-fpm.conf
3) This step originated from: http://hi.baidu.com/winsyk/blog/item/31a0154324a4610372f05d52.html
edit php-fpm.conf to locate PM. min_spare_server; PM. min_spare_servers = 5; number
you can also use sed-I's/; PM. min_spare_servers/PM. min_spare_servers/G'/etc/PHP/php-fpm.conf to replace
run php-FPM again for startup with the error:
Nov 20 17:57:14. 210553 [alert] [pool WWW] PM. max_spare_servers (0) must be a positive value
SED-I's/; PM. max_spare_servers = 35/PM. Max_spare_servers = 35/G'/etc/php-fpm.conf
run php-FPM again to start up. Error:
Nov 20 17:58:55. 248268 [Warning] [pool WWW] PM. start_servers is not set. it's been set to 20
SED-I's/; PM. start_servers = 20/PM. start_servers = 20/G'/etc/php-fpm.conf
run php-FPM again with no error prompted, boot successful.
4) edit the httpd. conf file and add the following lines:
# Vim/etc/httpd. conf
<Ifmodule fastcgi_module>
Fastcgiexternalserver/usr/local/Apache/cgi-bin/test-cgi-host 127.0.0.1: 9000
Addtype application/X-httpd-PHP. php
Addhandler PHP-FastCGI. php
Action PHP-FastCGI/cgi-bin/test-cgi
</Ifmodule>
5) run php-FPM to check the network status and check whether port 9000 is enabled.
#/Usr/local/PhP5/sbin/PHP-FPM
# Netstat-NTL
Active Internet connections (only servers)
PROTO Recv-Q send-Q local address foreign address State
TCP 0 0 127.0.0.1: 2208 0.0.0.0: * listen
TCP 0 0 127.0.0.1: 9000 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 111 0.0.0.0: * listen
TCP 0 0 0.0.0.0: 916 0.0.0.0: * listen
TCP 0 0 127.0.0.1: 631 0.0.0.0: * listen
TCP 0 0 127.0.0.1: 25 0.0.0.0: * listen
TCP 0 0 127.0.0.1: 2207 0.0.0.0: * listen
TCP 0 0: 3306: * listen
TCP 0 0: 80: * listen
TCP 0 0: 22: * listen
6) restart the HTTPd service and open the webpage to test whether PHP is successfully connected.
# Service httpd restart
---------------------------------------------------------------------------------
Install PHP accelerator ZendOptimizer-3.3.9
1) download and extract ZendOptimizer-3.3.9
# Tar-XF ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
2) Installation
# Cd ZendOptimizer-3.3.9-linux-glibc23-i386
#./Install. Sh
Press enter and enter the path of PHP. ini in the following interface.
Then press enter again, prompting you to confirm the HTTPd service again.
Press enter to complete installation.