Install FastCGI with PHP in Apache on CentOS 6

How to install FastCGI with PHP in Apache on CentOS 6.

Here’s a quick and simple way to get an Apache virtual host configured have FastCGI handle PHP. This is useful if you wish to use suEXEC or have tighter control over the usage of PHP. THis could be restricting certain PHP fuctions etc.

Just note that this document assumes CentOS 6 for all example code and references. Syntax, file locations and codes may vary based on your distribution.

Step 1: Install Packages

First step is make sure we have the required packages installed. Assuming you already have the PHP module installed, we’ll just need to install a couple of extra packages:

Step 2: Create Execution Environment

Create a fastcgi-bin directory, copy php-cgi and ensure file permissions are correct.

Step 3: Configure Apache

By following the following steps, we’re not globally setting PHP to be handled php FastCGI. We’ll only be configure a single virtual host to use FastCGI to handle PHP.

Paying specific attention to the following:

Step 4: Restart Apache

Before restarting Apache we should quickly test the config for any errors:

Finshing Up…

This guide completely skipped over configuring a PHP wrapper script. The purpose of a PHP wrapper script is to control specific functions of the PHP environment. If you wish learn more about PHP wrapper you can visit the following sites:


  1. gezginrocker   •  

    hey thanks a lot for the tutorial mate! the other tutorial I found was very complex & outdated. I have easily installed fastcgi in 2 minutes thanks to your tutorial. and it seems to be working. :)

  2. Serge   •  

    Hi Andrew and thank you VERY MUCH for the detail instruction – very useful and easy to setup !

    Why do you think that configuration of every directory is better ?

    I’d prefer to configure common Apache httpd.conf file to set PHP to be handled php FastCGI globally (why not ?)
    Could you extend a little your instructions to set FastCGI in a global way ?

    Thank you in advance for your comment,
    Have a nice day !

  3. sebbrochet   •  

    The title of your post is “Install FastCGI with PHP in Apache on CentOS 6″ but in fact you explain in great details how to install a _specific_ fastcgi implementation, using the mod_fcgid apache module.

    However there’s also another implementation using the mod_fastcgi apache module.

    The main difference, performance wise, is that mod_fastcgi can share the same PHP opcode cache between several thread running PHP code while mod_fcgid can’t. That translates, in most cases, to more connections served with mod_fastcgi than with mod_fcgid.

    More technical details here:



  4. Pingback: fastcgi with apache, virtualhost per user setup | keithyau

  5. hermest   •  

    thanks bro. this was usefull for me

Leave a Reply to sebbrochet Cancel reply

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

eight − 4 =

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