Migrating from PHP4 to PHP5: A strategy for hosts
If you have a shared hosting company and are still running PHP4, you might feel the pressure rising. Articles like ‘Now showing: PHP’s true colors’ basically tell you to make the switch and take the hit, but they do not give any advice how to handle this.
The basic problem is that you can inform your customers that you’re migrating to PHP5, but if you can’t provide a testing platform for your customers, how are they going to know if migrating will break their sites.
A few months ago I’ve posted an article about running multiple Apache instances with different PHP versions. In that article I showed how to make multiple configurations running Apache on different IP addresses. By using different ports instead of different IP addresses, we can give our customers a way to check their site before it goes live.
If you haven’t read the article, start with that. On step 2 ‘Create additional apache configuration files’ you need need to do it slightly different though. Follow the whole article, but in step 2 do (not using mod_macro):
Remove PHP4 from mods_enabled and the Listen directive from the ‘apache.conf’ file.
Create apache2-php4.conf:
Include /etc/apache2/apache2.conf Listen 192.168.1.50:80 LoadModule php4_module /usr/lib/apache2/modules/libphp4.so <IfModule mod_php4.c> AddType application/x-httpd-php .php .phtml .php3 AddType application/x-httpd-php-source .phps </IfModule>
Create apache2-php5.conf:
Include /etc/apache2/apache2.conf LockFile /var/lock/apache2/apache2-php5.accept.lock PidFile /var/run/apache2-php5.pid ErrorLog /var/log/apache2/error-php5.log Listen 192.168.1.50:8800 LoadModule php5_module /usr/lib/apache2/modules/libphp5.so <IfModule mod_php5.c> AddType application/x-httpd-php .php .phtml .php3 AddType application/x-httpd-php-source .phps </IfModule>
In this example replace ‘192.168.1.50′ with your own IP address. Restart Apache and it will start up 2 instances, one with PHP4 running on port 80 and one with PHP5 running on port 8800. Now you can send out a mailing to all your customers, reporting that you change to PHP5 in a number of weeks and that they should check if their website would experience problems by going to http://www.example.com:8800, where example.com should be replaced by their domain name.
This setup is not tested, so please tell me if it is not working.
01 Sep 2007 Arnold Daniels




Catch this article in French at http://g-rossolini.developpez.com/tutoriels/logiciels/plusieurs-apache-simultanes
The fine people hosting me and my customers at Dathorn are running both PHP4 and PHP5 as CGI on the same Apache server, requiring just an ‘AddHandler’ line in .htaccess to switch between them. I managed to do the same on my (Windoze) development machine and wrote a short how-to at http://forums.dathorn.com/showthread.php?t=2884 ; should do the trick on any *nix with Apache and mod_php4 already installed.
I architect/manage the system of a hosting company, Helder Hosting, myself. We also have PHP4 and PHP5 available. We use the multiple Apache instances method, so you can switch between versions by changing the IP in the DNS. Personally I prefer that method, because it gives the host more control. There is no need to touch the webdir of the customer.
When you only run PHP4 though you probably want to switch all websites except those who would experience problems. This method allows you to test just that.