PHP源碼安裝及配置——以fastCGI的方式與httpd整合

來源:互聯網
上載者:User

標籤:php fastcgi

    在前一篇博文中介紹了LAMP的安裝及配置。這裡專門介紹PHP以fastCGI的方式與httpd整合的情況下,具體如何編譯及配置。而且假定httpd、mysql均如前一篇博文介紹的安裝配置完畢。php也採取一樣版本的源碼包php-5.6.1.tar.bz2。


1.  編譯安裝php

# tar xf php-5.6.1.tar.bz2

# cd php-5.6.1

# ./configure --prefix=/usr/local/php --enable-sockets --enable-mbstring --enable-xml --enable-fpm --with-bz2 --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-mcrypt --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php.d

# make && make install


注:編譯時間請確保機器的記憶體大於1G,或者在./configure 的選項中加上“--disable-fileinfo”,否則可能出現編譯失敗的情況。


2.  為php提供設定檔

# cp php.ini-production /etc/php.ini


3.  配置php-fpm

a) 為php-fpm提供設定檔

     # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

b) 編輯php-fpm的設定檔,調整相關的運行參數作最佳化。當然使用預設值也能正常運行。
     # vim /usr/local/php/etc/php-fpm.conf
     配置fpm的相關選項為你所需要的值,並啟用pid檔案(如下最後一行):
       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

c) 為php-fpm提供SysV init指令碼,並將其添加至服務列表

       # 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
       # chkconfig php-fpm on

4.  啟動php-fpm服務,測試回合狀態

# service php-fpm start

# netstat -tnlp | grep php-fpm

預設情況下,fpm監聽在127.0.0.1的9000連接埠


5.  修改httpd的主設定檔httpd.conf

a) 啟用httpd的相關模組

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

b) 在相應的位置添加如下行

    AddType application/x-httpd-php  .php

    AddType application/x-httpd-php-source  .phps

c) 修改DirectoryIndex 的定義為:

    DirectoryIndex  index.php  index.html


6.  配置虛擬機器主機支援使用fcgi

在相應的虛擬機器主機中添加類似如下兩行:

ProxyRequests Off
      ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1

參數選項含義解釋

ProxyRequests Off:關閉正向 Proxy
ProxyPassMatch:把以.php結尾的檔案請求發送到php-fpm進程,php-fpm至少需要知道啟動並執行目錄和URI,所以這裡直接在fcgi://127.0.0.1:9000後指明了這兩個參數,其它的參數的傳遞已經被mod_proxy_fcgi.so進行了封裝,不需要手動指定。

舉例:

<VirtualHost *:80>
   DocumentRoot "/www/htdocs/test.com"
   ServerName www.test.com
   ServerAlias test.com

   ProxyRequests Off
   ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/htdocs/test.com/$1

   <Directory "/www/htdocs/test.com">
       Options none
       AllowOverride none
       Require all granted
   </Directory>
</VirtualHost>




本文出自 “被褐懷玉徳善人間” 部落格,請務必保留此出處http://deshanrenjian.blog.51cto.com/9324633/1561648

PHP源碼安裝及配置——以fastCGI的方式與httpd整合

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.