Lab Environment:
1.VMware Virtual Machine
2.linux Sub-Machine 3 units
3. Local test machine
Experimental Purpose:
The fastcgi mode allows dynamic language to be separated from static, and when the HTTP server encounters a dynamic program, it can be delivered directly to the fastcgi process to execute, and the resulting results are returned to the browser. This approach allows the HTTP server to handle static requests exclusively or return the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.
Experimental topology:
650) this.width=650; "title=" L) rnpfmqxren8[3@5t5iqu4.jpg "alt=" wkiol1p7yshxfzbxaaeitktjstq337.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m02/47/81/wkiol1p7yshxfzbxaaeitktjstq337.jpg "/>
The first two blogs are written to httpd compilation and MySQL compilation installation, which is not compiled here.
Compiling PHP
./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-pdomysql=mysqlnd--with-mysqli=mysqlnd-- With-openssl--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr --enable-xml--enable-sockets--enable-fpm--with-mcrypt=/usr/local/libmcrypt--with-config-file-path=/etc-- WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2
The last time you compiled and installed PHP was based on a module that was compiled as a httpd, where
--withapxs2=/usr/local/httpd/bin/apxs this sentence is to compile PHP into a httpd module, this time PHP is a standalone server, so this time when compiling--enable-fpm enable FPM.
Problems with compiling and installing PHP:
1. Prompt bzip2 to reinstall
As long as you are sure that BZIP2 has been installed, but also prompted the error, that is your bzip2-devel this package is not installed, with CD-ROM security
2. Compile the need to use mcrypt, compile sometimes prompt libmcrypt This package can not find, let reinstall
Download Libmcrypt This package, compile and install the./configure–prefix=/usr/local/libmcrypt, if you are also prompted to find
Libmcrypt, when compiling PHP, the parameters-with-mcrypt specify the path,--with-
Mcrypt=/usr/local/libmcrypt
To provide a configuration file for PHP:
# CP Php.ini-production/etc/php.ini
Configure PHP-FPM
Provide the SYSV init script for php-fpm and add it to the list of services:
# CP sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm# chmod +x/etc/rc.d/init.d/php-fpm# chkconfig--add php-fpm# CHKCO Nfig PHP-FPM on
To provide a configuration file for php-fpm:
# cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
To edit a php-fpm configuration file:
# vim/usr/local/php/etc/php-fpm.conf Configure FPM with the relevant options for the value you need and enable the PID file (the last line below): Pm.max_children = 50 maximum concurrency allowed to run concurrently Pm.start_ Servers = 5 How many idle processes are started at startup Pm.min_spare_servers = 2 Minimum idle processes pm.max_spare_servers = 8 maximum idle processes PID =/usr/local/php/var/run/php- Fpm.pid
Note: There is also a listen listening port, the port default is 9000, but the front IP must be the IP of your PHP server, do not be 127.0.0.1, should not appear the following error
650) this.width=650; "title=" EY ' K9d_h@2hf%b (z4@xyi) g.jpg "alt=" wkiom1p7ewgiq38yaabnb6hbcxe254.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m00/47/80/wkiom1p7ewgiq38yaabnb6hbcxe254.jpg "/>
By default, FPM listens on port 9000 of 127.0.0.1, and can also use the following command to verify that it is already listening on the appropriate socket. Here to use the PHP server ip:192.168.0.3
650) this.width=650; "Title=" 0bz3em ({zisbj~[yoi406 ' 1.jpg "alt=" wkiol1p7eq3ave5taaa9xmgq5tw166.jpg "src=" http:/ S3.51cto.com/wyfs02/m02/47/82/wkiol1p7eq3ave5taaa9xmgq5tw166.jpg "/>
The next step is to start php-fpm:
# service PHP-FPM Start
650) this.width=650; "title=" S ' HH2GT (3) 2nl{a_pq{tw16.jpg "alt=" wkiom1p7ed2bcn--aacyglsonfa443.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m01/47/80/wkiom1p7ed2bcn--aacyglsonfa443.jpg "/>
Configure httpd-2.4.9
Enabling the relevant modules for httpd
After Apache HTTPD 2.4 has a module specifically for the implementation of the FASTCGI, this module is mod_proxy_fcgi.so, it is actually as an extension of the mod_proxy.so module, so the two modules are loaded
View two modules
#ls/usr/local/httpd/modules
650) this.width=650; "title=" ' ~ (RBMKLDW)) q{9n7]xliu6.jpg "alt=" wkiol1p7e16wh1r3aadfrgzk0su095.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m00/47/82/wkiol1p7e16wh1r3aadfrgzk0su095.jpg "/>
Enable this module: Find and remove the "#" from the front
#vim/etc/httpd/httpd.conf
650) this.width=650; "title=" v]b}u4ilp[6y@}cbu1y4xuv.jpg "alt=" wkiol1p7e8rz79u2aadsc_bobjm360.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m01/47/82/wkiol1p7e8rz79u2aadsc_bobjm360.jpg "/>
If you want httpd to communicate with PHP in the FCGI protocol, you also need to httpd to work in reverse proxy mode, and configure the virtual host to support the use of fcgi
Add two lines similar to the following in the corresponding virtual host.
Proxyrequests OFF
Proxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/path/to/document_root/$1
Detailed
Proxyrequests off: Turn off the forward proxy
Proxypassmatch: Send a file request ending in. php to the PHP-FPM process, php-fpm need to know at least the directory and URI to run, so this is directly in the fcgi:// 127.0.0.1:9000 (where the IP address refers to the IP of the server where PHP is located) indicates these two parameters, and the other parameters have been encapsulated by mod_proxy_fcgi.so and do not need to be specified manually.
For example:
650) this.width=650; "title=" {t{mk1k87pc_or43) 2}vo7y.jpg "alt=" wkiol1p7fgtsuaalaadqrhb93b0260.jpg "src=" http:/ S3.51cto.com/wyfs02/m01/47/82/wkiol1p7fgtsuaalaadqrhb93b0260.jpg "/>
Edit Apache config file httpd.conf to allow Apache to recognize PHP-formatted pages and support PHP-formatted homepage
# vim/etc/httpd/httpd.conf
Add the following two lines
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps
Navigate to DirectoryIndex index.html, modified to:
DirectoryIndex index.php index.html
Test:
In the test, if there is a file not found this error page, the 80% you are the principle of misunderstanding, the user in the HTTPD request page, httpd see if it is PHP dynamic page to the PHP to deal with, after the processing of PHP will be passed to httpd , then pay attention to, according to the principle of understanding, httpd can not parse the file to the PHP server, this sentence means that the HTTPD server will not have PHP files, it just see that they can not resolve, the file sent to the PHP server. So, if you want to test, this PHP file is to be placed on the PHP server, as for the path that must be with the HTTPD server defined on the path of DocumentRoot.
650) this.width=650; "title="}}5 ' pzg$ho5jr2p%c7grmgv.jpg "alt=" wkiol1p7fq-q5f6aaafgkum97ds277.jpg "src=" http:/ S3.51cto.com/wyfs02/m00/47/82/wkiol1p7fq-q5f6aaafgkum97ds277.jpg "/>
This article is from the "Fish" blog, please be sure to keep this source http://kyfish.blog.51cto.com/1570421/1544981
PHP based on fastcgi mode and httpd communication