Tue, 25 Oct 2005

PHP4 and PHP5 under Windows

— SjG @ 4:02 pm

There have been other articles on this, but I wanted to post my own approach, just because it’s such an ugly — yet effective — hack.

I wanted PHP 4 and PHP 5 to both live happily on my Windows 2k machine, and work under Apache 1.3x. Install them in c:\php4 and c:\php5, and there you go. It’s easy to create an httpd.conf that takes a define, and figures out which PHP to load based upon that define.

But then both PHPs want to use the same php.ini file, specifically, c:\WINNT\php.ini. This is only a problem when you’re using PHP extensions, because one version will try to load the wrong ones. There are registry tricks, supposedly, and environment variable tricks to get different .ini files going, depending on version. None of ’em worked for me.

So I opened up vim, and edited my php4ts.dll, and replaced the “php.ini” string with “ph4.ini”. Now I happily have two PHP installs, each with its own .ini file, and everything is copacetic — except for all that software that breaks the newly enforced reference rules. But that’s another story.

5 responses to “PHP4 and PHP5 under Windows”

  1. Jason R. says:

    vim? What is vim and is it something I can get a hold of so that I can do this myself?

  2. SjG says:

    Vim is a version of the free “vi” editor. It comes as part of the Cygwin package (, or as its own download (

    You can do the edit in question with any editor that will handle binary files, though.

  3. Richard Quadling says:

    About to try this …

    Use php.ini for PHP4 and php-cgi/php-cli/php-isapi/php-apache .ini for PHP5.

    About to try this.

    Hold on.

  4. Doc Holiday says:

    Actually, if you have a recent machine, why not just install VMWare Player with one of the free installs of Debian or something. That way, you can have a full custom environment — different versions of PHP, MySQL, etc.

    For the base setup, this is all free. If you want to get fancy, you’ll have to buy the sofwtare.

  5. SjG says:

    Actually, even easier, is installing XAMPP. There’s a batch file that lets you swap between PHP 4 and 5, and it isolates the Apache, MySQL, and PHP installs in their own localized directory. If you want to go crazy, and have other versions of MySQL around, for example, you can have both XAMPP, EasyPHP, and probably others all installed at once. You just have to make sure you’re only running one at a time (i.e., don’t let them install as services, but launch them manually through their respective control apps).

    Easier than VMWare, and all free OSS.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.