First, what is fastcgifastcgi is a scalable, high-speed communication interface between Http server and the dynamic scripting language. Most http server support fastcgi, such as:nginx AAPACHE&NBSP;LIGHTTPD, etc... FASTCGI is supported by many languages. There is PHP. Second, nginx+fastcgi operation principle (1) Nginx does not support the direct invocation or parsing of external programs, all outsourced programs (including PHP) must be called through FASTCGI (2) fastcgi interface under Linux can ( Socket file way exists, then can IP), (3) in order to invoke the CGI program, also need a fastcgi wrapper, when Nginx send CGI request to this socket. The request is wrapper through the FastCGI interface, and then a new thread is derived, which invokes the external program or the script reads but returns the data . finally wrapper the data returned through the FastCGI interface. Passing the fixed socket to Nginx, and finally returning to the data sent by the client . nginx--> send a CGI request-->fastcgi (Warpper) received this request---> Derive a new thread---> Call an external program or script to return data--->wrapper to pass the data along a fixed socket to the nginx--> by Nginx to return this data to the user. Iii. installation and optimization of PHP and PHP-FPM &NBSP;&NBSP;&NBSP;PHP-FPM is also a third-party fastcgi process Management, which is developed as a PHP patch and compiled together into the PHP kernel when it is written. PHP-FPM is very good at dealing with high concurrency. It's a bit: it is to separate the dynamic language and the Http server (static and static separation), Http server mainly deal with quiescent requests, PHP-FPM processing dynamic requests. all PHP/PHP-FPM and nginx are often assembled onto a single machine to meet business requirements . Four, first install MySQL ( 1) First install MySQL database, PHP at compile time need a configuration of MySQL so php remote link mysql only use # cd /data/soft/# tar xf mysql-5.1.49.tar.gz -c tmp/# cd tmp/ mysql-5.1.49/#CONFOPTS = " --with-charset=utf8 --with-plugins=partition,federated,innobase,myisam --enable-static --enable-assembler --enable-thread-safe-client --with-client-ldflags=- All-static-ltinfo --with-mysqld-ldflags=-all-static-ltinfo --with-big-tables --with-mysqld-user =mysql --without-debug --without-ndb-debug --localstatedir=/usr/local/services/mysql-5.1.49/var --prefix=/usr/local/services/mysql-5.1.49 "#./configure $CONFOPTS >/dev/null# make >/dev/null && make install >/dev/null Five, Install PHP dependent libraries ①libxml2-2.7.7.tar.gz# cd /data/soft/#tar xf libxml2-2.7.7.tar.gz –C Tmp/# cd tmp/libxml2-2.7.7/#./configure --prefix=/usr/local/services >/dev/null#make >/dev/null && make install >/dev/null②curl-7.21.4.tar.gz# cd /data/soft/# tar xf curl-7.21.4.tar.gz -c tmp/# cd tmp/curl-7.21.4/#./configure --prefix=/usr/local/ services >/dev/null#make >/dev/null && make install >/dev/ null③jpegsrc.v8b.tar.gz# cd /data/soft/#tar xf jpegsrc.v8b.tar.gz –c tmp/#cd tmp/jpeg-8b/#./configure --prefix=/usr/local/services >/dev/null#make >/dev/null && make install >/dev/null④libpng-1.4.3.tar.gz# cd /data/soft/# tar xf libpng-1.4.3.tar.gz -C tmp/# cd tmp/libpng-1.4.3/#./configure --prefix=/usr/local/services >/dev/null#make >/dev/null && make install >/dev/null⑤freetype-2.4.1.tar.gz# cd /data/soft/# tar xf freetype-2.4.1.tar.gz -c tmp/# cd tmp/freetype-2.4.1/#./configure --prefix=/usr/local/services >/dev/null#make >/dev/null & & make install >/dev/null⑥libevent-2.0.10-stable.tar.gz# cd /data/soft/# tar xf libevent-2.0.10-stable.tar.gz –c tmp/# cd tmp/libevent-2.0.10-stable/#./ configure --prefix=/usr/local/services --disable-debug-mode >/dev/null#make >/dev/ null && make install >/dev/null⑦re2c-0.13.5.tar.gz# cd /data/soft/# tar xf re2c-0.13.5.tar.gz -c tmp/# cd tmp/re2c-0.13.5/#./configure -- Prefix=/usr/local/services >/dev/null#make >/dev/null && make install >/dev/null⑧libmcrypt-2.5.8.tar.gz# cd /data/soft/# tar xf libmcrypt-2.5.8.tar.bz2 -c tmp/# cd tmp/libmcrypt-2.5.8/#./configure --prefix=/usr/ Local/services >/dev/null#make >/dev/null && make install >/dev/null# cd libltdl/# ./ configure --prefix=/usr/local/services --enable-ltdl-install >/dev/null#make >/dev/ Null && make install >/dev/null VI, install PHP dependent library wget http://php.net/ distributions/php-5.3.13.tar.gzphp-5.3.13.tar.gz# cd /data/soft/# tar xf php-5.3.13.tar.gz -c tmp/#cd tmp/php-5.3.13/#CONFOPTS = "--enable-zend-multibyte -- Enable-mbstring --enable-sockets --enable-pdo --enable-zip --enable-fpm --with-gd --with-fpm-user=user_00 --with-fpm-group=user_00 --with-zlib --with-config-file-path=/usr /local/services/php-5.3.13/etc --with-libxml-dir=/usr/local/services --with-curl=/usr/local/services --with-png-dir=/usr/local/services --with-jpeg-dir=/usr/local/services --with-freetype-dir=/ Usr/local/services --with-mysql=/usr/local/services/mysql --with-pdo-mysql=/usr/local/services/mysql --with-mysqli=/usr/local/services/mysql/bin/ mysql_config --prefix=/usr/local/services/php-5.3.13 "# ./configure $CONFOPTS # make >/dev/null && make install >/dev/null compilation Error Resolution:/var/lib/mysql/ Mysql.sockconfigure: error: cannot find libmysqlclient under /usr. note that the mysql client library is not bundled anymore! WORKAROUND: CP -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so Seven, Installing the PHP Extension Module ①eaccelerator-0.9.6.1.tar.bz2# cd /data/soft/#tar xf eaccelerator-0.9.6.1.tar.bz2 -c tmp/#cd tmp/eaccelerator-0.9.6.1/#/usr/local/services/ php-5.3.13/bin/phpize #./configure --prefix=/usr/local/services/eaccelerator-0.9.6.1 -- enable-eaccelerator --with-php-config=/usr/local/services/php-5.3.13/bin/php-config > /dev/null#make >/dev/null && make install >/dev/null#mkdir /tmp/ Eaccelerator#chmod 777 /tmp/eaccelerator②memcached-1.4.13.tar.gz (server side to be installed before, the following compile extension module to use) # cd /data/soft/#tar xf memcached-1.4.13.tar.gz -c tmp/# cd tmp/ memcached-1.4.13/#./configure --enable-64bit --with-libevent=/usr/local/services --prefix=/usr/ Local/services/memcached-1.4.13 >/dev/null# make >/dev/null && make install >/dev/null③libmemcached-0.48.tar.gz# cd /data/soft/#tar xf libmemcached-0.48.tar.gz -c tmp/#cd tmp/libmemcached-0.48/#CONFOPTS = "--disable-libinnodb - -without-libinnodb-prefix --with-libevent-prefix=/usr/local/services --with-memcached=/usr/local/ services/memcached-1.4.13/bin/memcached --prefix=/usr/local/services "#./configure $CONFOPTS >/dev/null#make >/dev/null &aMp;& make install >/dev/null④igbinary-1.0.2.tgz# cd /data/soft/# tar xf igbinary-1.0.2.tar.gz -c tmp/#cd tmp/igbinary-1.0.2/#/usr/local/services/ php-5.3.13/bin/phpize#./configure --enable-igbinary --with-php-config=/usr/local/services/php-5.3.13 /bin/php-config >/dev/null#make >/dev/null && make install >/ Dev/null⑤memcache-3.0.5.tgz # cd /data/soft/# tar xf memcache-3.0.5.tgz -c tmp/#cd tmp/memcache-3.0.5/#/usr/local/services/php-5.3.13/bin/phpize#confopts= " -- enable-memcache --with-php-config=/usr/local/services/php-5.3.13/bin/php-config "#./configure $ confopts >/dev/null#make >/dev/null && make install >/dev/ NULL⑥MEMCACHED-1.0.2.TGZ (Note the order of installation, igbinary-1.1.1.tgz is a dependent library) # cd /data/soft/# tar xf Memcached-1.0.2.tgz -c tmp/# cd tmp/memcached-1.0.2/#/usr/local/services/php-5.3.13/bin/phpize#confopts= " --enable-memcached --enable-memcached-igbinary --enable-memcached-json --with-libmemcached-dir=/usr/local/ services --with-php-config=/usr/local/services/php-5.3.13/bin/php-config --prefix=/usr/local/ services "#./configure $CONFOPTS >/dev/null#make >/dev/null && make install >/dev/null⑦owlient-phpredis-2.1.1-1-g90ecd17.tar.gz# cd /data/soft/#tar xf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz -c tmp/# cd tmp/ owlient-phpredis-90ecd17/#/usr/local/services/php-5.3.13/bin/phpize #./configure --with-php-config=/ usr/local/services/php-5.3.13/bin/php-config >/dev/null#make >/dev/null && Make install >/dev/null Nine, copy configuration file:# cd /usr/local/services/php-5.3.13/etc# cp php-fpm.conf.default php-fpm.conf# cp /soft/php/php-5.3.13/php.ini-production php.ini1.php configuration file optimization and adjustment 1. Inside the php-fpm.conf adjustment.; listen = 127.0.0.1:9000listen = /tmp/php-cgi.tuge.sock # Accessed in a socke manner. Look at the way the IP port is.; default value: log/php-fpm.logerror_log = /data/php_log/tuge.php.error # Depending on the project name. Define different .sock and logs .# adjust the number of processes Pm.max_children: The number of PHP-FPM processes that are turned on in a static manner. Pm.start_servers: The number of start PHP-FPM processes under dynamic mode. Pm.min_spare_servers: The minimum number of PHP-FPM processes under dynamic mode. Pm.max_spare_servers: The maximum number of PHP-FPM processes under dynamic mode. 2. Add the extension module in php.ini . Added at the tail: [eaccelerator]zend_extension=]/usr/local/services/php-5.3.13/lib/php/extensions/ No-debug-non-zts-20090626/eaccelerator.so "eaccelerator.shm_size=" "eaccelerator.cache_dir="/tmp/eaccelerator " eaccelerator.enable= "1" eaccelerator.optimizer= "1" eaccelerator.check_mtime= "1" eaccelerator.debug= "0" Eaccelerator.filter= "" eaccelerator.shm_max= "0" eaccelerator.shm_ttl= "0" eaccelerator.shm_prune_period= "0" eaccelerator.shm_only= "0" eaccelerator.compress= "1" EacceleratoR.compress_level= "9" expansion module added extension = memcached.soextension = redis.soextension = memcache.soextension = igbinary.so 10, start php-fpm#cd   ... /SBIN#./PHP-FPM 11, nginx configuration file Adjustment #vim /usr/local/services/nginx-0.8.55/conf/vhost/vhost.zhangyi.com # Multiple localtion can be specified for different instruction processing, which is the sock location ~ \ of the specified PHP. php$ { fastcgi_pass unix:/tmp/php-cgi.zhangyi.sock; #修改这里 fastcgi_index index.php; include fastcgi_params; fastcgi_param&nbSp script_filename $document _root$fastcgi_script_name; fastcgi_param SERVER_NAME $http _host; fastcgi_ignore_client_abort on; } 12, restart Nginux#cd /usr/local/services/nginx-0.8.55/sbin#./nginx -s reload 13, test #cd /data/www#mv index.html index.php#vim index.php<?php phpinfo ();? > Login in Firefox browser