10
votes

I need to do some work on a legacy system that requires PHP 5.2

I already have XAMP 1.7.3 installed but this version has PHP 5.3.

Since this a work I might do for a couple of times in the next months, I was thinking about installing a XAMP version that runs PHP 5.2 At the same time I'm involved into some work that requires me to use PHP 5.3, so I just can`t uninstall my current XAMP version and install one that uses PHP 5.2

On XAMPP Download Website it's pretty clear that on installing any XAMPP version it will remove previous one. I've done some research but couldn't find a way to get around this.

I managed to find phpswitch under /Applications/XAMPP/xamppfiles/bin/ and using it's list action showed me that I only have PHP 5.3.1 installed and active. I tried to figured out on how to download/install/activate PHP 5.2 using phpswitch but had no success.

So what I'm looking for is a way to install multiple XAMPP or installing PHP 5.2 and activating it for XAMPP (either through phpswitch or another way)

7
There is nothing that PHP 5.2 can do but 5.3 cannot, so just use 5.3 and keep in mind differences between these versions while writing your PHP 5.2 code.Māris Kiseļovs

7 Answers

13
votes

You can install parallel versions of XAMPP - one for each major version of PHP. Just don't run both at the same time.

Install each instance of XAMPP in it's own folder.

I do this under a folder called

XAMPPInstalls/XAMPP182-PHP54 /XAMPP183-PHP55/

In each XAMPP folder, you'll find an .exe to launch the controller for that specific XAMPP stack. I've created shortcuts to those, renamed them to 'XAMPP182-ControlPanel' and 'XAMPP183-ControlPanel' and placed those on my desktop.

When I need to run local site on PHP5.4, I click on XAMPP182-ControlPanel and fire up the Apache and MySQL servers.

When I need to switch a local site to PHP5.5, I click on XAMPP182-ControlPanel and shut down the Apache and MySQL servers, then I click XAMPP182-ControlPanel and fire up the Apache and MySQL servers in that stack.

This takes just a few seconds.

Also, I use 'soft-linking' so that I do all my configuration for my local web sites in one folder - then create a 'junction' (i.e. a source folder that replicates itself in the Apache configs for each XAMPP stack).

There is a really good article on this called 'Practical Development 2: Working Environment' by Marco Dings in the Joomla! Community Magazine on how to set up your work environment to run multiple local XAMPP installs, multiple local web sites using 'name based hosting,' and how to keep it all organized.

I don't use Ding's set-up exactly - I've tweaked to get my local web projects even more organized and streamlined - but my set-up is based on Ding's approach.

NOTE: The article, while in the Joomla! Community Magazine, is not specific to Joomla!, so you can use this set-up for whatever PHP/Apache/MySQL projects you are working on.

Now there are lots of ways to do this (e.g. using Oracle's VM Virtual Box), but that might be overkill unless you need to replicate your remote hosting environment 'exactly.' For example, if you are running a 'dedicated host' and want to closely replicate dedicated host's environment and set up as closely as possible, then you'd go with VM Virtual Box Set-Up - this allows you to run multiple VM's (i.e. different set-ups) and then clone the exact set-up to your live server. Again, overkill if most of your projects are going to 'shared hosting' environments as you don't have much control over the set-up anyways.

Parallel installation of multiple instance of XAMPP is much much much simpler and you can set it up as per Ding's article. It should cover your requirements.

I've mentioned Oracle VM VirtualBox because you should at least know about it as an option.

1
votes

You could always use VirtualBox (or similar) to create an instance with 5.2 on it and then when you're done with old work, just dump the VB instance with no ill affect on your current system.

1
votes

You have a couple of options. Either use a virtual box to run virtual environments: one with PHP 5.2 and another with PHP 5.3. Or, if you're comfortable with installing PHP you could install the various version of PHP you need, and set up a symbolic link to the version you want to use at that time.

0
votes

I don't know anything about Apache or PHP, but I find MacPorts helpful for installing multiple versions of software that is usually difficult to install multiple versions of, such as python or GCC.

port search php

shows that MacPorts can provide PHP 5.2, 5.3, and 5.4. Such installations are put into /opt, so they will leave any other PHP installations alone.

0
votes

I just want to add in case you run any os (mine is Yosemite) do the same but working on the xamppfiles folder inside the main XAMPP folder (so the path to work with is different), you can both then change configure.ini and possibly file related (complicated) or (easy but dirty) name the version you want to use xamppfiles and the other whatever, and then create 2 separate alias for the manager to start (one for each xampp version). Like this is a little confusing but if someone needs it I can describe both approaches step by step.

0
votes

Previous answers didn't work well for me, but there's a rather elegant solution over on the Apache Friends Forum, though it took me a bit to get things working properly. Some highlights:

  • By installing multiple versions of XAMPP, you can get various versions of the PHP CGI module. That said, keep in mind that your config files and databases may need to be restored if you run multiple installers, so backup and plan accordingly.
  • Make sure that those CGIs are allowed to do their thing by adding a block something like this in your httpd-xampp.conf file (I put mine at the end):

    <Directory "/Applications/XAMPP/xamppfiles/bin">
        Require all granted
        Options +ExecCGI
    </Directory>
    

    Keep in mind that depending on the version of Apache that XAMPP is using, your syntax may vary a bit.

  • Now find this section in your httpd.conf file and make sure the corresponding Include is uncommented, like so:

    # Virtual hosts
    Include etc/extra/httpd-vhosts.conf
    
  • You can now add entries in your httpd-vhosts.conf file for each version of PHP that you want to use, something like this:

    <VirtualHost test54.yourdomain.com:80>
        ServerName test54.yourdomain.com
        ....
        ScriptAlias /xampp-bin /Applications/XAMPP/xamppfiles/bin
        <FilesMatch "\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>
        Action application/x-httpd-php /xampp-bin/php-cgi-5.4.31
        ....
    </VirtualHost>
    <VirtualHost test55.yourdomain.com:80>
        ServerName test55.yourdomain.com
        ....
        ScriptAlias /xampp-bin /Applications/XAMPP/xamppfiles/bin
        <FilesMatch "\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>
        Action application/x-httpd-php /xampp-bin/php-cgi-5.5.35
        ....
    </VirtualHost>
    ....
    

    (In the version of XAMPP that I use, there also happens to be a symbolic link in that bin directory called simply php-cgi which points to the most recent CGI installed, and I add a block for that, too.)

  • Add corresponding entries to your hosts file, like so:

    127.0.0.1           test54.yourdomain.com
    127.0.0.1           test55.yourdomain.com
    

That should do it. I love the resulting flexibility, and the fact that the various versions of PHP that I have configured as simply available when I need them.

0
votes

We can use Xampp-VM for multiple xampp installation. I wanted to use multiple php versions for older and new projects without changing or wasting my time in configuration.

So If your Xampp is already installed. Install new Xampp-VM from here

https://www.apachefriends.org/download.html

This will guide you, how to setup Xampp-Vm.

https://www.apachefriends.org/blog/new_xampp_20170628.html