Choose PHP4/PHP5 per Directory?

Is there any way to switch between the use of PHP4 and PHP5 on a directory basis?

I thought I had this working before, but I was either high at the time I reached that conclusion, or something changed and removed my ability to do so.

I’m currently using PHP5 as CGI, but I need to drop back to PHP4 so I can make use of the fact that OpenSSL is actually compiled into the two PHP4 installation (apache module and as CGI).

Does anyone have something like this working?

.php4 files will always get parsed by PHP4 (Apache-module) and .php5 by PHP5 (CGI).

I guess, you could also compile your own PHP5 with support for OpenSSL.

[color=#000000]DreamHost Promo Code[/color]: [color=#CC0000]Save $50[/color] with the promo code DREAMTEAM

I saw that feature in suggestions, but I don’t seem agree that it works.
A file named index.php4 that contains <?php phpinfo(); ?> still shows 5.0.4

Do you have anything in your .htaccess that would be setting this functionality?

No, but I have the domain set up to run PHP4 as standard. The .php5 extension will then trigger PHP5.

[color=#000000]DreamHost Promo Code[/color]: [color=#CC0000]Save $50[/color] with the promo code DREAMTEAM

I’m still completely and totally lost.
That is a php4 domain, and yet, .php5 isn’t even being parsed.


  1. Are you REALLY sure you don’t have anything in your .htaccess ?
  2. Is there some settings I’m missing?
  3. What server are you on? Think I need to contact support?

Hi Jason,

I just checked my settings again. I have the domain running with php4 as an Apache module. Nothing in my .htaccess. I’m on the Karnov server.

You can see an example on, where I have 4 different php versions running on the same domain.

If switching to the Apache module doesn’t solve your problem, I would contact support for clarification.

[color=#000000]DreamHost Promo Code[/color]: [color=#CC0000]Save $50[/color] with the promo code DREAMTEAM

Support said that it’s not possible to do what I’m attempting to do.
Perhaps you just proved them wrong? :stuck_out_tongue:

I will admit that I have it running PHP4 as CGI, so that may be the difference.
Besides there’s a lot of things that work php related in your .htaccess when it’s an apache module, and not as CGI.

Keep your eyes around here, I might need your assistance later ;).

I just tried and thing with php4 and php5 will not work on my domain.

Still there is a way to have your folders run 4 and 5, you just have to setup subdomain for certain folder and tell which php you would like to use. This is good enough for me.


Can be done through .htaccess.

Each .htaccess can have the lines:
Action cust-php
AddHandler cust-php .php

Just replace with the path to the specific PHP binaries you wish to use. This will overwride any PHP settings defined within Apache (even the module). One .htaccess file per directory (which you want to change)

Here’s how I do mine, note I have multiple versions set:

[quote]Action gpcentre-php /cgi-bin/php.cgi
Action java-php /cgi-bin/jphp.cgi
Action dh-php /cgi-system/php5.cgi
Action dh-php4 /cgi-system/php.cgi

AddHandler dh-php .dphp .dpcgi
AddHandler dh-php4 .dphp4 .dpcgi4
AddHandler java-php .jphp .jpcgi
AddHandler dh-php .php .pcgi
AddType application/x-httpd-php-source .sphp .phps[/quote]
The .sphp and .phps is using the Apache module PHP Syntax parser.

You are my SAVIOR!

You looking for a job?
DreamHost needs to fire Trey and HIRE YOU.


The best part? It doesn’t even have to be per directory, it can be per file extension!!!


Huh. Would you mind if I asked what your custom jphp and gpcentre php versions are?

LMAO … I’m not that much of a savior…

gpcentre-php is my custom built PHP5. I built PHP5 a while before DH gave the option to use PHP5. I don’t really use it anymore but might if DH doesn’t upgrade to PHP5.1.1.

java-php is PHP5 compiled with a Java bridge. Highly unstable and requires persistant processes so this is purely a “to play with” extension for me. I don’t run the Java bridge 24/7.