Note: an alternative to FastCGI is fcgid (mod_fcgid), which is better than FastCGI. Check out:
http://groups.drupal.org/node/27174
http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html
===========================================
今天把 FreeBSD web 改成了 apache worker 其實之前就已經這麼做了,只是今天加上 mod_fastcgi 我是參考 DarkKiller 大神 apache22 (worker) + mod_fastcgi + php5-fcgi,之前就把 Server 換成了 php5-fcgi,只不過我是搭配 Lighttpd,效能方面還不錯,可以參考這篇:[FreeBSD] Lighttpd + PHP + mod_proxy + FastCGI,那因為用 lighttpd 的外掛模組真的太少,不像 apache 支援這麼多 module,重點是還缺少了 .htaccess 這個功能,所以大大降低大家使用 lighttpd,近期內會把全部 server 換成 apache2 搭配 mod_fastcgi,那底下寫一下作法了:
基本上利用 FreeBSD 的 ports 安裝就可以了:
1. 先安裝 apache with MPM = worker
cd /usr/ports/www/apache22
make WITH_MPM=worker install clean
pkg_info | grep apache
#
# 會出現
#
apache-worker-2.2.9_5 Version 2.2.x of Apache web server with worker MPM.
make WITH_MPM=worker install clean
pkg_info | grep apache
#
# 會出現
#
apache-worker-2.2.9_5 Version 2.2.x of Apache web server with worker MPM.
cd /usr/ports/lang/php5; make install clean
cd /usr/ports/lang/php5-extensions; make install clean
cd /usr/ports/lang/php5-extensions; make install clean
cd /usr/ports/www/mod_fastcgi
make install clean
make install clean
#
# 把下面這行 umark 掉
#
# Server-pool management (MPM specific)
Include etc/apache22/extra/httpd-mpm.conf
# 把下面這行 umark 掉
#
# Server-pool management (MPM specific)
Include etc/apache22/extra/httpd-mpm.conf
mpm_worker_module 那段:
ThreadLimit 512
StartServers 1
MaxClients 512
MinSpareThreads 1
MaxSpareThreads 512
ThreadsPerChild 512
MaxRequestsPerChild 0
StartServers 1
MaxClients 512
MinSpareThreads 1
MaxSpareThreads 512
ThreadsPerChild 512
MaxRequestsPerChild 0
到 /usr/local/etc/apache22/httpd.conf 把底下這一段的註解拿掉
LoadModule fastcgi_module libexec/apache22/mod_fastcgi.so
#
FastCgiConfig -maxClassProcesses 1
ScriptAlias /fcgi-bin/ "/usr/local/www/fcgi-bin/"
<Directory /usr/local/www/fcgi-bin/>
SetHandler fastcgi-script
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#
AddHandler php-fastcgi .php
Action php-fastcgi /fcgi-bin/php
FastCgiConfig -maxClassProcesses 1
ScriptAlias /fcgi-bin/ "/usr/local/www/fcgi-bin/"
<Directory /usr/local/www/fcgi-bin/>
SetHandler fastcgi-script
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#
AddHandler php-fastcgi .php
Action php-fastcgi /fcgi-bin/php
然後再建立: /usr/local/www/fcgi-bin 這個資料夾,裡面擺入執行檔 php 內容是:
#!/bin/sh
PHPRC="/usr/local/etc"
export PHPRC
PHP_FCGI_CHILDREN=128
export PHP_FCGI_CHILDREN
exec /usr/local/bin/php-cgi
PHPRC="/usr/local/etc"
export PHPRC
PHP_FCGI_CHILDREN=128
export PHP_FCGI_CHILDREN
exec /usr/local/bin/php-cgi
這個架構下,httpd 會產生 512 threads 處理連線,並產生一個 fastcgi 的 socket 處理 PHP 程式,這個 socket 會由 128 隻 php-cgi 聽,且這 128 隻的 cache 會共用。參考網站:gslin 大神 :apache22 (worker) + mod_fastcgi + php5-fcgi
Reference: http://blog.wu-boy.com/2008/09/13/388/
No comments:
Post a Comment