HTTP Server: Apache 2.4

PHP method #2: FastCGI

by ross at 12:36:12 on August 1, 2014
# cd /usr/ports/www/mod_fcgid
# make install clean

Edit httpd.conf, make sure this line is present and not commented out:

LoadModule fcgid_module libexec/apache24/

If you have enabled and want to use SUEXEC also add this:

LoadModule suexec_module libexec/apache24/

These modules should be commented out or absent: php5_module, proxy_fcgi_module.

Create apache24/modules.d/020_mod_fcgid.conf:

<IfModule fcgid_module>
    <IfModule dir_module>
        DirectoryIndex index.php

    <FilesMatch "\.(php|phtml|inc)$">
        Options +ExecCGI
        SetHandler fcgid-script

    # This should be less than or equal to PHP_FCGI_MAX_REQUESTS in php.fcgi
    FcgidMaxRequestsPerProcess 999

    # This should be equal to PHP's cgi.fix_pathinfo, which is 1 by default
    FcgidFixPathinfo 1 

    # PHP's post_max_size, upload_max_filesize
    FcgidMaxRequestLen 200000000

    # PHP's max_execution_time, max_input_time
    FcgidBusyTimeout 600
    FcgidIdleTimeout 600
    FcgidIOTimeout 600

You will need to create a CGI script for every virtual host you have. Suppose the DocumentRoot of your host is /home/ In this case create /home/ file:


exec /usr/local/bin/php-cgi
# chmod 755 /home/

If SUEXEC is used don't forget to chown the directory:

# chown -R myuser:mygroup /home/

Now place this in your <VirtualHost> section:

    <IfModule fcgid_module>
        FcgidWrapper "/home/"
        <IfModule suexec_module>
            SuexecUserGroup myuser mygroup

Restart Apache:

# service apache24 restart