Running PHP4 and 5 on Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djn
    Senior Member
    • Mar 2004
    • 140

    Running PHP4 and 5 on Windows

    Hello forum!
    I've just managed to have PHP4 and PHP5 running at the same time on my Windows box, so that I can replicate the Dathorn setup. It took me some effort, so I thought I might save somebody the trouble of discovering the whell all over again.

    I started with a working Apache installation (v. 1.3.29 on port 80, manually started instead of as a service, located in C:\Apache) with PHP 4.4.1 (as Apache module, located in C:\php, with php.ini in the webserver directory). Windoze is XP Pro SP2.

    Step 1 - Change PHP4 to be loaded as CGI
    a) Move the existing php.ini from C:\Apache to C:\php
    b) Open C:\Apache\conf\httpd.conf with a text editor
    c) Find the line with 'LoadModule php4_module C:/Apache/php4apache.dll' and comment it out with a leading #
    d) Same for the line with 'AddModule mod_php4.c'
    e) Add line 'ScriptAlias /php/ "C:/php/" '
    f) Add line 'Action application/x-httpd-php /php/php.exe'
    g) Add line 'AddHandler application/x-httpd-php .php'
    h) Save

    Step 2 - Test that PHP4 is still working
    a) Make directory C:\Apache\htdocs\test
    b) Create file phpinfo.php there
    c) Write into file '<?php phpinfo(); ?>
    d) Start Apache and point browser to 'http://localhost/test/phpinfo.php'
    e) OK, PHP4 is still working as expected

    Step 3 - Install PHP5
    a) Open latest PHP5.x.x-Win32.zip (mine is 5.2.2)
    b) Extract everything to C:\php5 preserving the folder structure
    c) Edit C:\php5\php.ini-dist with the correct include_path ('C:/php/includes' for me), extension_dir ('C:/php5/ext') and session.save_path('C:/windows/temp'); save as C:\php5\php.ini
    d) Reopen C:\Apache\conf\httpd.conf for editing
    e) Add line 'ScriptAlias /php5/ "C:/php5/" '
    f) Add line 'Action application/x-httpd-php5 /php5/php-cgi.exe'
    g) Add line 'AddHandler application/x-httpd-php5 .php5'
    h) Save again

    Step 4 - Test that PHP5 works
    a) Copy C:\Apache\htdocs\test\phpinfo.php to phpinfo.php5 in same folder
    b) Stop and start Apache again
    c) Point browser to 'http://localhost/test/phpinfo.php5'
    d) You should see a big 'PHP Version 5.x.x' now

    Step 5 - Switch PHP version with .htaccess file
    a) Point again browser to 'http://localhost/test/phpinfo.php' (to make sure nothing got broken)
    b) Write into a text file 'AddHandler application/x-httpd-php5 .php'
    c) Save as 'C:\Apache\htdocs\test\.htaccess'
    d) Refresh browser
    e) Here it says PHP Version 5.x.x
    f) Reopen .htaccess and comment out with a leading #
    g) Refresh browser
    h) PHP4 is back!

    What to avoid:
    a) No matter what the PHP documentation, the included install.txt and everybody else says, do NOT create the Environment variable PHPRC in Control Panel->System->Properties->Advanced, nor add 'SetEnv PHPRC C:\php5' to httpd.conf
    b) Make sure you have no stray php.ini file in the Apache directory, in the Windows one or everywhere in your PATH

    That's all, folks. The same .htaccess will now switch you from PHP4 to PHP5 both on your Windows box and up there on Dathorn.

    Have fun.
  • djn
    Senior Member
    • Mar 2004
    • 140

    #2
    Just a quick note to warn that the resulting setup does NOT obey per-directory configuration by mean of a php.ini file. Use ini_set() instead.

    Comment

    • AndrewT
      Administrator
      • Mar 2004
      • 3653

      #3
      Very nice write up. Thank you for posting it!

      Comment

      Working...