Local .htaccess strangely allowed running PHP in CGI/FastCGI mode in Apache under shared hosting environment
The problem is not that Apache rewrite rules in the .htaccess
file won't work when running PHP as a CGI vs. an Apache module. It's just you can't use the .htacess
file to set PHP values when it's ran as a CGI. Instead you have to have a separate php.ini file that has your settings changed in it. Within my own shared hosting account, which runs PHP as a CGI, I make use of FastCGI and have the following in my .htaccess
file:
<IfModule !mod_php.so>
AddHandler myphp-script .php
Action myphp-script /cgi-bin/myphp.fcgi
</IfModule>
Then in my accounts /cgi-bin/
directory I place the myphp.fcgi
script with chmod 755
containing:
#!/bin/sh
# This ensures PHP doesn't try to run it's own
# process manager.
export PHP_FCGI_CHILDREN=0
# Execute PHP with my php.ini config file
exec /path/to/system/cgi-bin/php -c ~/myconf/php.ini
I still have a <IfModule mod_rewrite.c>
section in my .htaccess
file to handle rewriting some old URI paths to the new URI structure to maintain old links that are cached in search engines.