Php – Running PHP script through CGI with Apache… how

apache-2.2PHP

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.

Best Answer

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.

Related Topic