Running PHP4 and PHP5 together
I wanted to test my scripts in PHP5, but I didn't have access to any PHP5 dev machine, so I needed to install PHP5 on my own computer. However, I didn't want to install it over PHP4, because I need that as well (most web hosts still only support PHP4).
So I installed PHP5 along side with PHP4, using only one Apache. If you want to do this as well, then follow these instructions (they're easy).
- Download and install PHP5, and make sure you install PHP5 in a new directory, e.g. C:\PHP5
- Copy the php.ini-dist from the PHP5 directory to C:\Windows and rename it to php.ini. You can remove the previous php.ini that was there already.
- Next, you have to edit the http.conf file, and create a new virtual host, that looks like this:
Listen 83
ServerName localhost
ServerAdmin me@localhost
DirectoryIndex index.html index.php
ErrorLog logs/error.log
# http://httpd.apache.org/docs-2.1/mod/core.html.en#limit
Order allow,deny
Allow from all
DocumentRoot "C:/www/project-a/"
ScriptAlias /cgi-bin/ "C:/php5/"
Action php5-script /cgi-bin/php-cgi.exe
AddHandler php5-script .php .html
I've high-lighted all the important bits.
- If everything went correctly, you can now go to http://localhost:83 and use PHP5. If you want PHP4, just go to http://localhost. That's all :)
It's working perfectly for me, and I've already uncovered a few (small) bugs in my scripts and components.
August 31st, 2005 at 11:25 am
You forgot two mention two things:
If someone wants to use their loaded DLLs with both versions, they are NOT compatible. Therefore, one would need to use the following parameter within their VirtualHost directives:
SetEnv PHPRC –path_to_PHP5_php.ini_file–
If the person has not yet set their Listen directive in their httpd.conf file, by default it’s 80, and on Windows (at least v1.3.29, yes I have to upgrade) it is commented out. Using your Listen 83 (or any other number) will render the default site (ala PHP4) unavailable.
Also, access logs can be helpful, use the CustomLog directive for that.
August 31st, 2005 at 12:41 pm
Yes, you’re right. I had to do some more fiddling to get everything running smoothly.
September 1st, 2005 at 9:13 am
The following was what I used:
ServerName 127.0.0.1
ServerAdmin
DocumentRoot “C:/Apache/htdocs”
DirectoryIndex index.html index.htm index.shtml index.shtm index.php index.cgi
ErrorLog logs/error5.log
CustomLog logs/access5.log combined
SetEnv PHPRC C:/php5
ScriptAlias /php/ “c:/php5/”
AddType application/x-httpd-php .php
Action application/x-httpd-php “/php/php-cgi.exe”
I found the AddHandler didn’t work. Figured I’d post this as a full example since Google had this listed as a top link.