WordPress with FCGID in Apache2.4

FCGID allows PHP to run outside of the Apache process. It also allows the PHP process to run as the user who owns the scripts. This is useful for WordPress as it allows the installation of plugins and themes without the need to enter FTP credentials.

To get it running is sometimes tricky as it is not always obvious (e.g. from a log file) where a problem lies. This post documents how I got it working after a few headaches. This assumes WordPress has already been installed at /var/www/mysite.

First, install the necessary packages

aptitude install apache2-mpm-worker php5-cgi libapache2-mod-fcgid

Enable the fcgid module in Apache. Disable php5 mod if it is enabled, so that the fcgid module is used to handle PHP requests.

a2enmod fcgid
a2dismod php5

Ensure the wordpress user/group owns all files in the wordpress site.

chmod -R wordpress:wordpress /var/www/mysite

Create the php-fcgi-starter script

/var/www/php-fcgi-scripts/php-fcgi-starter

with the following contents

#!/bin/sh
PHPRC=/etc/php5/cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php

This also needs to be owned by the wordpress user/group.

Finally, put the necessary bits in Apache site configuration file:

    <IfModule mod_fcgid.c>
        SuexecUserGroup wordpress wordpress
        <Directory /var/www/mysite>
            Options +ExecCGI
            AllowOverride All
            AddHandler fcgid-script .php
            FCGIWrapper /var/www/php-fcgi-scripts/php-fcgi-starter .php
            Require all granted
        </Directory>
    </IfModule>
Article last modified on October 24, 2015 at 8:52 pm.

Leave a Reply

Your email address will not be published. Required fields are marked *