Q. I'd like to switch from mod_php5 to mod_fastcgi. I'm using FreeBSD 7 release along with following software:
+ Apache 2.2
+ PHP as mod_php5
+ MySQL DB 5.1.23 server
How do I configure php as FastCGI server?
A. mod_fcgid has a newprocess management strategy, which concentrates on reducing the numberof fastcgi server, and kick out the corrupt fastcgi server as soon aspossible. It is a binary compatibility alternative to Apache module mod_fastcgi; so your existing fastcgi programs do not need to be recompiled. mod_fcgid supports suEXEC.
Why run PHP5 as mod_fcgi / mod_fastcgi?FastCGI as has some serious advantages over mod_php5:
You can do user level separations. You can enable quotas per user. Limit users by processes and CPU consumption.
chroot security call per user possible
According to several reports fastcgi works much faster than mod_php and cgi mode.
Step # 1: Install mod_fcgidMake sure your ports are upto date:
# portsanp fetch update
Install mod_fcgid:
# make install clean
Make sure php supports FastCGIMake sure php-cgi binary exists and it is compiled with fastcgi support:
# cd /usr/ports/lang/php5
# make showconfig | grep -i FASTCGI
Output:
FASTCGI=on "Enable fastcgi support (CGI only)"Another way to test fastcgi support, enter:
# /usr/local/bin/php-cgi -v
Output:
/usr/local/bin/php-cgi -v
PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cgi-fcgi) (built: Mar 6 2008 09:15:41)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
If you don't see word cgi-fcgi, recompile php with fastcgi support by visiting /usr/ports/lang/php5
# cd /usr/ports/lang/php5
# make config
# make install clean
Step # 3: Load mod_fcgi moduleOpen your httpd.conf file located at /usr/local/etc/apache22/ directory:
# vi /usr/local/etc/apache22/httpd.conf
Load mod_fcgi module:
LoadModule fcgid_module libexec/apache22/mod_fcgid.so
Configure mod_fcgi
AddHandler fcgid-script .fcgi
FCGIWrapper /usr/local/bin/php-cgi .php
Find your DocumentRoot directory configuration option that read as follows:
Append following two lines:
SetHandler fcgid-script
FCGIWrapper /usr/local/bin/php-cgi .php
Options ExecCGI
At the end configuration should read as follows: # This should be changed to whatever you set DocumentRoot to.
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
SetHandler fcgid-script
FCGIWrapper /usr/local/bin/php-cgi .php
Options ExecCGI
Allow from all
Step # 4: Disable mod_php5Find line that read as follows:
LoadModule php5_module libexec/apache22/libphp5.so
Comment out line:
#LoadModule php5_module libexec/apache22/libphp5.so
Also make sure following two line (mime type) exists:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Save and close the file.
Step # 5: Restart Apache22Finally, restart apache web server:
# /usr/local/etc/rc.d/apache22 restart
Step # 5: Test mod_fcgiUse following small program to verify mod_fcgi is working properly:
You must see Server API as CGI/FastCGI as well as following screen: http://bbs.bsdlover.cn/attachments/month_0804/20080407_c64e61b02cc05ec82f32JbmYXPfOnUWi.png
freebsd-php5-cgi-fcgi-mod-fcgi.png