Thursday, March 31, 2011

How can one run multiple versions of PHP 5.x on a development LAMP server?

(Sorry for the poorly-phrased title.)

I need to test my PHP applications with multiple versions of PHP 5.x, such as PHP 5.0.0 and PHP 5.2.8.

Is there a way that I can configure a development LAMP server so I can quickly test applications with multiple versions of PHP5?

From stackoverflow
  • One way to do this is to have your main version of php set up with mod_php and run all of the others through fast cgi on different ports (i.e. 81, 82, 83 etc). This won't guarantee totally consistent behavior though.

    Wayne Khan : An idea: For PHP 5.2.1, use port 10521. For 5.0.0, use 10500 :)
    Cd-MaN : An other option would be to run it using CGI (or FastCGI) under different paths - ie /cgi500/, /cgi528/, ...
  • Having multiple instances of apache + php never really tickled my fancy, but it probably the easiest way to do it. If you don't feel like KISS ... here's an idea.

    Get your apache up and running, and try do configure it like debian and ubuntu do it, eg, have directories for loaded modules. Your apache conf can use lines like this:

    Include /etc/apache2/mods-enabled/*.load
    Include /etc/apache2/mods-enabled/*.conf
    

    Then build your first version of php, and give it a prefix that has the version number explicitly contained, eg, /usr/local/php/5.2.8, /usr/local/php/5.2.6 ...

    The conf/load would look something like this:

    php5.2.6.load

    LoadModule php5_module /usr/local/php/5.2.6/libphp5.so
    

    php5.2.8.load

    LoadModule php5_module /usr/local/php/5.2.8/libphp5.so
    

    To switch versions, all you have to do is change the load and conf files from the directory apache does the include on for the ones for another version. You can automate that with a simple bash script (delete the actual file, copy the alternate versions file in place, and restart apache.

    One advantage of this setup is the everything is consitent, so long you keep the php.ini's the same in terms of options and modules (which you would have to do with CGI anyway). They're all going through SAPI. Your applications won't need any changes whatsoever, nor need to use relative URLs.

    I think this should work, but then again, i haven't tried it, nor am i likely to do so as i don't have the same requirements as you. Do comment if you ever do try though.

  • I have just successfully downgraded from PHP5.3 on Ubuntu 10.

    To do this I used the following script:

    #! /bin/sh
    php_packages=`dpkg -l | grep php | awk '{print $2}'`
    
    sudo apt-get remove $php_packages
    
    sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list
    
    sudo mkdir -p /etc/apt/preferences.d/
    
    for package in $php_packages;
    do echo "Package: $package
    Pin: release a=karmic
    Pin-Priority: 991
    " | sudo tee -a /etc/apt/preferences.d/php
    done
    
    sudo apt-get update
    
    sudo apt-get install $php_packages
    

    For anyone that doesn't know how to run scripts from the command line, here is a brief tutorial:

    1. cd ~/
    2. mkdir bin
    3. sudo nano ~/bin/myscriptname.sh
    4. paste in the script code I have posted above this
    5. ctrl+x (this exits and prompts for you to save)
    6. chmod u+x myscriptname.sh
    

    These 6 steps create a script in a folder called "bin" in your home directory. You can then run this script by calling the following command:

    ~/bin/myscriptname.sh
    

    Oulia!

    Home this helps some of you!

    For reference, here is where I got the script: PHP5.2.10 for Ubuntu 10

    There are several people on there all confirming that this works, and it worked a treat for me.

0 comments:

Post a Comment