Enable FastCGI on a per site basis.

These instructions assume that you have compiled PHP with FastCGI enabled (if not recompile with EasyApache) and that you configured your server to use SuPHP and Apache SuExec as the default in WHM. This will allow you or your users to enable FastCGI (mod_fcgid) on a per site basis from the users cPanel.

In our case we found FastCGI helps with high traffic Wordpress sites and other high traffic PHP sites. We don’t want FastCGI enabled for all sites by default because of the memory consumption. So for us this works well.

First:

nano /usr/local/apache/conf/php.conf

add the following to the top of that file:

# Fastcgi configuration for PHP5
LoadModule fcgid_module modules/mod_fcgid.so
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php

Next:

nano /usr/local/cpanel/cgi-sys/php5

add the following to that file:

#!/bin/sh

# If you customize the contents of this wrapper script, place
# a copy at /var/cpanel/conf/apache/wrappers/php5
# so that it will be reinstalled when Apache is updated or the
# PHP handler configuration is changed

exec /usr/bin/php

Next:

chown root:wheel /usr/local/cpanel/cgi-sys/php5
chmod 755 /usr/local/cpanel/cgi-sys/php5

and now do a full Apache restart:

service httpd stop
service httpd start

That’s it!

Now you or your users can login to the sites cPanel account, click the Apache Handlers icon and under handler add fcgid-script and under extension add .php then click the add button.

3 thoughts on “Enable FastCGI on a per site basis.

  1. Thank you so much for these instructions. I found them to be invaluable when setting this up on my own servers. I’ve seen a marked decrease in server load thanks to this and it plays very well with the custom php.ini path code I’m using.

    Two questions…
    1) Have you been able to find a way to have the php.conf mod and wrapper script persist after an easyapache
    2) Do your SuPHP sites now report the ‘Server API’ as ‘CGI/FastCGI’ as well? I’ve done testing and SuPHP is definitely being used to serve the pages (SuPHP_ConfigPath works for instance), but the misreported API bothers me…

  2. Yo Red.. Thanks, an article on your site helped me figure it out. I haven’t found a way to make the changes in php.conf stick. I really don’t think it is possible right now when using easyapache since it builds the php.conf file based on the profile with no template support. Maybe they will make a template soon.

    The wrapper script may be possible by making a copy at: /var/cpanel/conf/apache/wrappers/php5

    (I haven’t tried it though).

    I’m pretty sure php will display ‘CGI/FastCGI’ once php is compiled with fastcgi support. The API string is just reporting what the php engine is compiled to support, not what wrapper is being used. My servers with fastcgi compiled also show the same thing, regardless of the site using fastcgi or suphp. I checked an older server just now without fastcgi compiled and it shows just ‘cgi’ which makes sense.

    Note: If you need help keeping your fastcgi processes under control see these instructions on the cpanel forum.

  3. Thanks for getting back to me. I did try adding the wrapper to the wrappers folder, but it only copies from there when using rebuild_phpconf to set fcgid as the default. Setting SuPHP (or doing an easyapache when SuPHP is the default) deletes the wrapper :( . Not too big an issue, I can always just write a script to reset the config after an easyapache.

    Glad to hear I’m not the only one seeing the API line show up ‘wrong’!

    That forum post has great info, thanks!

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>