PHP5 + fastcgi + apache2.2 ... how to for FreeBSD?

Michael Powell nightrecon at
Tue Oct 20 11:14:38 UTC 2009

Marc G. Fournier wrote:

> Is there one somewhere?  I'm finding *alot* of Debian ones dealing with
> their whole apget stuff, but would like to find something that "speaks
> normally" :)

Install your choice of flavor of Apache. Me, I'm using the event-mpm for 
testing to verify the way to use non-thread safe PHP with a threaded server 
is FastCGI.

Install lang/php5 with various CLI options, as opposed to and instead of 
mod_php. This is set of options I used:

# This file is auto-generated by 'make config'.
# No user-servicable parts inside!
# Options for php5-5.2.11

Do not try and use MAILHEAD and SUHOSIN together; that combination is 
broken. Install the /lang/php5-extensions you require. Currently there seems 
to be a problem with, and since I don't use/need it's 
commented out of my extensions.ini.

Install www/mod_fcgid from ports. In httpd.conf use:

LoadModule fcgid_module libexec/apache22/

instead of the usual:

LoadModule php5_module        libexec/apache22/

Also, further down in httpd.conf:

# This should be changed to whatever you set DocumentRoot to.
<Directory "/usr/local/www/apache22/data">



# added to enable mod_fcgid

<IfModule mod_fcgid.c>
  AddHandler fcgid-script .fcgi .php
  SocketPath /var/run/fcgidsock/
  IPCConnectTimeout 10
  IPCCommTimeout 20
  OutputBufferSize 0

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
<IfModule dir_module>
    DirectoryIndex index.html index.php

If all went well you should be able to restart Apache and be in business. A 
phpinfo(); should execute and provide details. Any problems the quickest way 
to check PHP is to just execute php -v at a shell prompt. If it doesn't 
segfault it will print out a short descriptive output text.

I believe this is better than the usual script based approach you will 
locate on the web. It starts/spawns PHP as a long running process when 
Apache starts instead of starting a new CGI each time PHP script is 

The mod_fcgid is configurable:

I believe this project was fairly recently folded into the 
umbrella, but when I began it was separate and standalone. The docs on the 
Apache site look like they are for the upcoming 2.3 update to 2.2, and there 
may be discrepancies present. I had originally used the docs from the old 
site and I don't know if they are even still available.


P.S. - Also, if you need to use Alias they will look like this:

Alias   /xcache-admin   "/usr/local/share/examples/xcache/admin/"
<Directory "/usr/local/share/examples/xcache/admin/">
    #SetHandler None
    FCGIWrapper /usr/local/bin/php-cgi .php
    Options ExecCGI
    Order allow,deny
    Allow from
    Deny from none

More information about the freebsd-questions mailing list