Both PHP4 and PHP5 on same server

DennisCitus

Verified User
Joined
Mar 18, 2004
Messages
45
Location
TeleCity 2, Amsterdam
A client of mine wants to use certain php5 functions.

Is it possible to install php5 and by a simple change in DirectAdmin in his virtualhost.conf-file for him to run php5 instead of php4?

I am running 130 domains. I want 1 to use PHP5, and all others should use PHP4.

Has anybody done this before? Is it possible? What difficultaties am I to experience?
 
This has been discussed previously on these forums.

You leave apache alone, to use php4 as it's already set up to do, and you set up php5 to run as a separate language, calling it as php5.

Jeff
 
Well, the thing with PHP5 as a CGI on on DA is that by default. all user .cgi scripts (so aswell with the PHP5-CGI) is executed under SuEXEC circumstances. Apparently PHP5 doesnt like SuEXEC.. so you get the premature end of script stuff.

I tried to fix this months ago, but still no solution. Im also stuck on this.
 
I've found this guide pretty interesting:
http://wiki.coggeshall.org/Main/RunningPHP4AndPHP5Concurrently

I love it. It seems so simple.

I have already enable mod_proxy on the main Apache (which is running PHP4) and I have added the ProxyRequests off to not enable the proxy by default.

Then, at VirtualHost level, I could be able to use ProxyPass and ProxyPassReverse to point to the second instance of Apache (the one listening localhost and running PHP5).

The problem I don't know how to customize the VirtualHosts in the httpd.conf file for the second instance of the Apache service. Note this service would be listening localhost only.

Would this technique based on mod_proxy be possible when running a lot of Virtual Hosts on the server?
 
ugh, I finally managed to run PHP4 and PHP5 (as apache modules) on the same machine with 2 apache processes. The second process listening port 81 and using mod_rewrite to transparently redirect requests from one server to the other (port 80 to port 81). Using mod_rewrite means I can decide to run PHP4 or PHP5 per directory.

However, it's quite tricky and very difficult to maintain.

More or less, this is what I did:

  1. I was already running Apache 1.3.x and PHP4 (on a RedHat box).
  2. wget PHP5 into the customapache dir.
  3. Copy build to build.php5 and configure.php to configure.php5

    Edit build.php5 to set the PHP version to 5.0.4

    Edit configure.php5 and add the following parameters:

    --prefix=/usr/local/php5 \
    --exec-prefix=/usr/local/php5 \

    Note 1: This way I can use build to deal with PHP4 and build.php5 to deal with PHP5.
    Note 2: PHP4 and PHP5 get installed in different directories. Location of php.ini files:
    PHP4: /usr/local/lib/php.ini
    PHP5: /usr/local/php5/lib/php.ini
  4. Create a copy of the httpd binary

    cd /usr/sbin
    cp httpd httpd.php5
  5. Create a new startup script for the second Apache service:

    cd /etc/rc.d/init.d
    cp httpd httpd.php5

    Edit httpd.php5 to make it use the new binary and different .lock and .pid files.

    Also added the following argument to the httpd startup command:

    -f /etc/httpd/conf/httpd.php5.conf
  6. Create a new set of .conf files for the second Apache process

    cd /etc/httpd/conf
    cp ips.conf ips.php5.conf
    cp httpd.conf httpd.php5.conf

    Edit the new .conf files to remove all references to port 443 (I didn't wanted SSL) and changing all references to port 80 to use port 81.

    Removed all Includes from the bottom of the httpd.php5.conf file to avoid setting up all domains/subdomains for the second Apache service.

    Insert the Virtual Hosts corresponding to the domains/subdomains that I wish to use PHP5 and make them use port 81 (remove VHosts corresponding to SSL).

    Make sure httpd.conf loads the PHP4 module and httpd.php5.conf loads the PHP5 module.

    Edit httpd.conf and make it load the mod_proxy module. Also added the following statemenst to make sure it is disabled by default:

    <IfModule mod_proxy.c>
    ProxyRequests Off
    </IfModule>

  7. Finally, in the documents root of those domains I wish to use PHP5 create an .htaccess file to redirect requests from port 80 to port 81.

    RewriteEngine On
    RewriteCond %{SERVER_PORT} ^80$ [NC]
    RewriteCond %{REQUEST_FILENAME} ^(.*).php$ [NC]
    RewriteRule (.*) http://www.example.com:81/$1 [P,L]

    Note the use of the [P] flag. This is the Proxy Throughput feature of mod_rewrite. It requires mod_proxy installed on the first Apache service.

Well, I did it just to test PHP5 on my server. I don't think it can be used on a production server. Too tricky and very difficult to maintain.
 
Last edited:
Back
Top