Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Our current setup has PHP scripts being served by Apache using mod_php. We have just developed a new script that needs to be run through CGI (it's using pcntl to fork off some processes) instead of mod_php. Can someone give me an example configuration for this? Ideally we'd be able to have all the scripts run through mod_php except this one, but if we have to run them all through, then I can live with that.

Server details: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4 with Suhosin-Patch

The current configuration is about as straight-forward as they come (/etc/apache2/sites-available/default):

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
    <Directory /var/www/>
        Options FollowSymLinks MultiViews
        Order allow,deny
        allow from all

    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined

Thanks, in advance, for the help.

share|improve this question
up vote 4 down vote accepted

Don't use CGI: it works much slower than mod_php. The script that needs to fork can be launched using shell commands (system() function) and fork to it's heart's content :)

If you still want CGI, here's a hint how to execute SOME scripts with CGI handler with .htaccess file: Running php4 and php5 along side each other.

share|improve this answer

CGI is a COMMON GATEWAY INTERFACE ... i.e. you don't need to set it up for particular languages. However, Apache normally determines what to do with a file based on the filename extension (e.g. file.cgi versus file.php)

Your Apache configuratin is most likely already setup to handle CGI programs, you probably only need to do two things

Allow CGIs to be run from whatever directory you're in

<Directory /path/to/dir>
    Options +ExecCGI

Setup CGI for the file extension you want (e.g. blah.phpcgi)

AddHandler cgi-script .phpcgi
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.