標籤:編譯安裝lamp之配置httpd以fastcgi方式與php整合
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
make
make install
[[email protected] php-5.6.24]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 複製啟動指令碼
[[email protected] php-5.6.24]# chmod +x /etc/init.d/php-fpm
[[email protected] php-5.6.24]# chkconfig --add php-fpm
[[email protected] php-5.6.24]# chkconfig php-fpm on
[[email protected] php-5.6.24]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 複製一個設定檔給php-fpm
[[email protected] php-5.6.24]# vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 50 最多有多少個子進程
pm.start_servers = 5 剛啟動時有幾個空閑進程
pm.min_spare_servers = 2 最少有幾個空閑進程
pm.max_spare_servers = 8 最多有幾個空閑進程
pid =/usr/local/php/var/run/php-fpm.pid 定義pid檔案
service php-fpm start
------------------------------------------------------
fpm預設評鑑在9000連接埠
配置httpd
-
啟用httpd的相關模組
在Apache httpd 2.4以後已經專門有一個模組針對FastCGI的實現,此模組為mod_proxy_fcgi.so,它其實是作為mod_proxy.so模組的擴充,因此,這兩個模組都要載入
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
-
配置虛擬機器主機支援使用fcgi
在相應的虛擬機器主機中添加類似如下兩行。
ProxyRequests Off 關閉apache的正向 Proxy功能
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1 把以.php結尾的檔案請求發送到php-fpm進程,php-fpm至少需要知道啟動並執行目錄和URI,所以這裡直接在fcgi://127.0.0.1:9000 後指明了這兩個參數,其他的參數的傳輸已經被mod_proxy_fcgi.so進行了封裝,不需要手動指定。
Apache httpd 2.4 以前的版本中,要麼把PHP作為Apache的模組運行,要麼添加一個第三方模組支援PHP-FPM實現。
列如:
<VirtualHost *:80>
DocumentRoot "/www/a.org"
ServerName a.org
ServerAlias www.a.org
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/a.org/$1
<Directory "/www/a.org">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
--------------------------------------------------------
[[email protected] php-5.6.24]# cp php.ini-production /etc/php.ini
[[email protected] local]# vi /etc/httpd/httpd.conf
#DocumentRoot "/usr/local/apache/htdocs" 注釋掉中心主機
#Virtual hosts 啟用虛擬機器主機
Include /etc/httpd/extra/httpd-vhosts.conf
[[email protected] local]# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/www/a.org"
ServerName www.a.org
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/a.org/$1
<Directory "/www/a.org">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/a.org-erro_log"
CustomLog "/var/log/httpd/a.org-access_log" combined
</VirtualHost>
[[email protected] local]# vim /etc/httpd/httpd.conf
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 啟用
LoadModule proxy_module modules/mod_proxy.so 啟用
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-httpd-php .php 添加此行
AddType application/x-httpd-php-source .phps 添加此行
<IfModule dir_module>
DirectoryIndex index.php index.html 讓主也變支援index.php
</IfModule>
[[email protected] local]# apache/bin/apachectl start
[[email protected] a.org]# mv index.html index.php
然後還需要安裝xcache
[[email protected] xcache-3.2.0]# cp config.m4 ../php/bin/
[[email protected] bin]# ./phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[[email protected] xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make
[[email protected] xcache-3.2.0]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
[[email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d/xcache.ini xcache的設定檔
[[email protected] xcache-3.2.0]# vim /etc/php.d/xcache.ini
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so
本文出自 “營運成長路” 部落格,謝絕轉載!
編譯安裝LAMP之配置httpd以FastCGI方式與php整合