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/mod_fcgid.so

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

LoadModule suexec_module libexec/apache24/mod_suexec.so

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
    </IfModule>

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

    # 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
</IfModule>

You will need to create a CGI script for every virtual host you have. Suppose the DocumentRoot of your host is /home/example.com/public. In this case create /home/example.com/cgi-bin/php.fcgi file:

#!/bin/sh
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS

exec /usr/local/bin/php-cgi
# chmod 755 /home/example.com/cgi-bin/php.fcgi

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

# chown -R myuser:mygroup /home/example.com

Now place this in your <VirtualHost> section:

    <IfModule fcgid_module>
        FcgidWrapper "/home/example.com/cgi-bin/php.fcgi"
        <IfModule suexec_module>
            SuexecUserGroup myuser mygroup
        </IfModule>
    </IfModule>

Restart Apache:

# service apache24 restart

 

Comments