PHP以FastCGI方式與LAMP整合

來源:互聯網
上載者:User

標籤:fastcgi php lamp

1、系統內容:

[[email protected] ~]# cat /etc/issueCentOS release 6.4 (Final)Kernel \r on an \m [[email protected] ~]# uname -r2.6.32-358.el6.x86_64[[email protected] ~]# ifconfig | grep Bcast:          inet addr:192.168.0.200  Bcast:192.168.0.255  Mask:255.255.255.0

2、httpd 2.4源碼安裝:

請猛戳:httpd 2.4源碼安裝

3、mysql 5.5通用二進位包安裝:

請猛戳:mysql 5.5通用二進位包安裝

4、編譯安裝php,開啟fpm:

[[email protected] php-5.5.20]# pwd/root/software/php/php-5.5.20[[email protected] php-5.5.20]# ./configure --prefix=/usr/local/php5.5 --enable-mbstring --enable-xml  --enable-fpm --enable-sockets --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2#--enable-fpm              開啟php-fpm#--enable-maintainer-zts   此選項已刪除,因php是已獨立方式運行[[email protected] php-5.5.20]# make && make install

為php提供設定檔、為php-fpm提供設定檔及為php-fpm提供啟用指令碼:

[[email protected] php-5.5.20]# cp php.ini-production /etc/php.ini[[email protected] php-5.5.20]# cp /usr/local/php5.5/etc/php-fpm.conf.default /usr/local/php5.5/etc/php-fpm.conf[[email protected] php-5.5.20]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm[[email protected] php-5.5.20]# chmod +x /etc/rc.d/init.d/php-fpm[[email protected]zhaochj php-5.5.20]# chkconfig --add php-fpm[[email protected] php-5.5.20]# chkconfig --list php-fpmphp-fpm         0:off 1:off 2:on  3:on  4:on  5:on  6:off

啟動php-fpm及驗證php-fpm服務:

[[email protected] php-5.5.20]# service php-fpm startStarting php-fpm  done[[email protected] php-5.5.20]# ps aux | grep php-fpm

5、配置httpd,讓其成為fastcgi用戶端,並把httpd配置成虛擬機器主機方式工作:

啟用mod_proxy.so及mod_proxy_fcgi.so兩個模組:

[[email protected] php-5.5.20]# vim /etc/httpd24/httpd.conf……省略LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so……省略

配置httpd.conf檔案,讓其對php檔案的支援:

[[email protected] php-5.5.20]# vim /etc/httpd24/httpd.conf    ……省略    AddType application/x-compress .Z    AddType application/x-gzip .gz .tgz    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] php-5.5.20]# vim /etc/httpd24/httpd.conf#DocumentRoot "/usr/local/apache24/htdocs"   #注釋此行,關閉中心主機……# Virtual hostsInclude /etc/httpd24/extra/httpd-vhosts.conf   #啟用此行,開啟虛擬機器主機檔案

配置虛擬機器主機設定檔:

[[email protected] php-5.5.20]# vim /etc/httpd24/extra/httpd-vhosts.conf#注釋最後的</VirtualHost>容器,在最後新增下面配置:<VirtualHost *:80>     DocumentRoot "/web/zhaochj.com"     ServerName www.zhaochj.com     ProxyRequests Off     ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/web/zhaochj.com/$1     <Directory "/web/zhaochj.com">        Options none        AllowOverride none        Require all granted     </Directory></VirtualHost>

準備網頁檔案目錄,建立測試頁面:

[[email protected] php-5.5.20]# mkdir -p /web/zhaochj.com[[email protected] php-5.5.20]# vim /web/zhaochj.com/index.php <?php     phpinfo();?>

重新啟動httpd:

[[email protected] php-5.5.20]# /usr/local/apache24/bin/apachectl -k stop[[email protected] php-5.5.20]# /usr/local/apache24/bin/apachectl -tSyntax OK[[email protected] php-5.5.20]# /usr/local/apache24/bin/apachectl -k start

訪問測試頁面:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/12/wKiom1TGPUqx_ZolAAH0Cqnd7bY904.jpg" title="5555.png" alt="wKiom1TGPUqx_ZolAAH0Cqnd7bY904.jpg" />

6、最佳化php5,啟用php5內建的代碼緩衝機制opcache,不再使用xcache了:

[[email protected] php-5.5.20]# vim /etc/php.ini……省略[opcache]zend_extension = /usr/local/php5.5/lib/php/extensions/no-debug-non-zts-20121212/opcache.soopcache.enable=1opcache.memory_consumption = 64opcache.interned_strings_buffer = 8opcache.max_accelerated_files = 4000opcache.revalidate_freq = 60opcache.fast_shutdown = 1opcache.enable_cli = 1……省略

重新啟動php-fpm:

[[email protected] php-5.5.20]# service php-fpm restart

測試opcache是否啟用:

[[email protected] php-5.5.20]# /usr/local/php5.5/bin/php -m

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/59/12/wKiom1TGQKOySAxnAAHOzX6Nh4I037.jpg" title="666.png" alt="wKiom1TGQKOySAxnAAHOzX6Nh4I037.jpg" />

本文出自 “SNAIL” 部落格,請務必保留此出處http://357742954.blog.51cto.com/368705/1608573

PHP以FastCGI方式與LAMP整合

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.