Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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>
    <Directory /var/www/>
        Options FollowSymLinks MultiViews
        Order allow,deny
        allow from all
    </Directory>

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

Thanks, in advance, for the help.

share|improve this question

2 Answers 2

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

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

AddHandler cgi-script .phpcgi
share|improve this answer

Your Answer

 
discard

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.