Conditional .htaccess based on apache server API

508 Views Asked by At

I'm having trouble with .htaccess, specifically changing the include_path value. On my dev server PHP is ran as a module, so I can use:

php_value  include_path "/whatever/path/i/want"

Now when I migrated to the real server, PHP is ran as CGI/FastCGI, so my last trick doesn't work, so i've learned the hard way and got it all working using apache handlers so it loads a custom php.ini with the include path changed:

AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi

Now here comes the question. I need a codition block for each case, so it uses a handler if is executing as CGI/FastCGI or php_value if is as a module.

Found this for fastcgi but didn't make it work.

<IfModule fastcgi_module>
   AddHandler php5-fastcgi .php
   Action php5-fastcgi /cgi-bin/php.fcgi
</IfModule>

If there is another way to change include_path in both cases not depending on how is PHP executed, and not hardcoding it into the code, would be much aprecciated.

2

There are 2 best solutions below

0
On BEST ANSWER

.user_ini file should help you in case of CGI/FastCGI. Normally it's ignored for mod_php.

0
On

Thank you for answering I've solved my problem like this.

<IfModule mod_php5.c>
   php_value  include_path "path/I/want"
</IfModule>
<IfModule !mod_php5.c>
   AddHandler php5-fastcgi .php
   Action php5-fastcgi /cgi-bin/php.fcgi
</IfModule>

Anyway I didn't know about user.ini, still its good to know exists another solution.