Install PHP in CGI mode on Apache 2.x

Running PHP in CGI mode on Apache 2.x

I was running PHP as a module under Apache and decided to try the cgi mode. The instruction all over the web are pretty simple.
Add the following to your httpd.conf:

ScriptAlias /php52/ "E:/A22/php520/"
SetEnv PHPRC "E:/A22/php520/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php52/php-cgi.exe"

The SetEnv line is useful to indicate were to look for your php.ini first.

Well that might work for you, but it did not for me. Here are the additional steps I had to take:

  • In order to use the "Action" instruction:
LoadModule actions_module modules/mod_actions.so
  • In order to use the "SetEnv" instruction:
LoadModule env_module modules/mod_env.so
  • In order to use the "ScriptAlias" instruction:
LoadModule alias_module modules/mod_alias.so
  • In order to use PHP as a cgi:
LoadModule cgi_module modules/mod_cgi.so

Done with the modules.

  • Now to run to execute php-cgi.exe you need to set the appropriate access permsiions with something like:
<Directory "E:/A22/php520/">
Options ExecCGI 
Order allow,deny
Allow from all
</Directory>