【遷移】Apache 運行 PHP 的軟體包組合

因為要搭 roundcube,不想用 mod_php,所以在水木上詢問了這個問題,得到 JulyClyde@,cybergene@, adoal@ 的指點,在這裡再總結下。

  1. 內嵌方式:libapache2-mod-php5 + apache2-mpm-prefork,mod_php 目前還不是多線程安全的,不能用於 apache2-mpm-worker。mod_php 是運行 PHP 代碼效率最高的方式,但是據說內嵌了 mod_php 的 apache child 在服務靜態文件時因 mod_php 消耗大量內存而不值,所以只建議將內嵌了 mod_php 的 apache server 服務純 php 請求。對於其它內嵌模塊,也有類似的準則,比如 mod_perl。
  2. CGI 方式:apache2-mpm-prefork + mod_cgi(在 apache2.2-bin 包中) 或者 apache2-mpm-worker + mod_cgid (在 apache2.2-bin 包中),第二種組合是現在推薦的方式。
  3. FastCGI 方式:
  • apache2 + libapache2-mod-fastcgi + php5-cgi/php5-fpm/

  • apache2 + libapache2-mod-fcgid + php5-cgi
  • apache2.3 + mod_proxy_cgi + php5-fpm

php5-cgi 既可以作為普通 php 解釋器被以命令行形式啟動,也可以作為 external FastCGI server 形式啟動:

$ php-cgi -h
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file> [args...]
-a Run interactively
-b <address:port>|<port> Bind Path for external FASTCGI Server mode
-C Do not chdir to the scripts directory
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value bar
-e Generate extended information for debugger/profiler
-f <file> Parse <file>. Implies `-q
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
-T <count> Measure execution time of script repeated <count> times.

而 php5-fpm 只支持 external FASTCGI server 模式。mod_fcgid 和 php5-fpm 均有 fastcgi 進程管理功能,是比較推薦使用的。mod_fastcgi 現在是不推薦的。

nginx 不直接支持 CGI 方式,所以需要 fcgiwap 作為一個 cgi server 運行 CGI 程序。spawn-fcgi 是運行 FastCGI程序的方式,對於 PHP 而言不如 php-fpm,見 php-fpm.org/about/

推薦閱讀:

查看原文 >>
相关文章