2

Is there any way I could have php 4 and 5 installed in the same server, while keeping the same ".php" extension for both, and making it so only a specific folder (+subfolders) in the server run under php4?

I have CentOS 5.5 x64 with whm/cpanel, so I can install both with EasyApache, that part is not an issue.

Reason I want this is to keep an old script working; it's encoded with Zend and upgrading to php 5.3.x breaks it, it will only work on 5.2 (or 4.x), as it needs to be re-encoded if I am to run it on 5.3 (not an option). Decoding it didnt work quite well either, so I think the php4/5 approach would be a working solution, if I could restrict 4 to a folder and not have to change the extensions (obviously the script would fail with ".php4" because of hard-coded paths and filenames).

my current php.conf, handled by SuPHP

# SuPHP configuration for PHP5
LoadModule suphp_module modules/mod_suphp.so
suPHP_Engine on
AddType application/x-httpd-php5 .php5 .php .php3 .php2 .phtml
<Directory />
    suPHP_AddHandler application/x-httpd-php5
</Directory>

# SuPHP configuration for PHP4
AddType application/x-httpd-php4 .php4
<Directory />
    suPHP_AddHandler application/x-httpd-php4
</Directory>
hikari
  • 143
  • 1
  • 5

1 Answers1

1

According to the Apache documentation, AddHandler/AddType can be used in a directory context which means you should be able to simply do something like the following in the Apache config:

LoadModule php5_module modules/libphp5.so
LoadModule php4_module modules/libphp4.so

AddHandler php5-script .php
AddType    text/html .php

<Directory /home/somedir>
     AddHandler x-httpd-php4 .php
</Directory>

Note that depending on your installation you may have slightly different setup lines for php4/5 (check your existing config). If you already have php4 and 5 setup then you'd just need the entry.

uesp
  • 3,384
  • 1
  • 17
  • 16
  • My config is a bit different because php is handled by suPHP. I tried to edit my php.conf a few ways, but ended up having not even php5 work. How should I change the conf in this case? edited main question to properly format config file. – hikari Mar 27 '11 at 18:36
  • I would start by getting PHP4 and 5 to work separately first and then combine them to make sure they work together. In your configuration example if you rename all your PHP4 scripts to .php4 you should be able to get what you want. Alternatively, you can try my approach by using the AddType handlers within directory entries. I also found http://www.directadmin.com/forum/showthread.php?t=13953&page=3 which may help you. – uesp Mar 27 '11 at 22:04