2

I am using a shared web hosting service. Running phpinfo, I can see the Server API shows CGI/FastCGI rather than Apache 2 Handler.

In this article: http://docs.joomla.org/Should_PHP_run_as_a_CGI_script_or_as_an_Apache_module%3F

It says 'If your server is configured to run PHP as an Apache module, then you will have the choice of using either php.ini or Apache .htaccess files, however, if your server runs PHP in CGI mode then you will only have the choice of using php.ini files locally to change settings, as Apache is no longer in complete control of PHP.'

I think it's really strange that the rewrite rules in the .htaccess that I created have been working perfectly while it's running in CGI mode. Why is this happening?

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .