ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

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).

  1. Download and install PHP5, and make sure you install PHP5 in a new directory, e.g. C:\PHP5
  2. 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.
  3. 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.

  4. 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.

3 Responses to “Running PHP4 and PHP5 together”

  1. Brendon Kozlowski Says:

    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.

  2. Dennis Pallett Says:

    Yes, you’re right. I had to do some more fiddling to get everything running smoothly.

  3. Brendon Kozlowski Says:

    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.

Leave a Reply