Over a million developers have joined DZone.
Platinum Partner

Running Multiple Versions of PHP

· Web Dev Zone

The Web Dev Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

When I advise people about upgrading their PHP version, I say things like "just run your test suite with the new version" "just grab the new version and try your site with the built-in webserver". A couple of people recently have asked for more detail on how to actually achieve these things so here's a quick primer on getting new PHP without touching anything to do with your existing PHP installation.

Install Your New PHP Version

(These instructions are for *nix systems; I have literally no idea how it works on Windows)

You will want to download the source code of your desired version of PHP, then compile it. The key thing here is that we'll put this version of PHP in a different location than your operating system would like to put PHP by default - and so we'll avoid overwriting anything.

Go and choose your version from http://php.net/downloads.php. Download it into its own directory somewhere and extract the files.

Now we'll configure the source, but here is the key ingredient: we set a prefix so that it'll be installed into a separate directory and not interfere with anything. Make a command like this with your path in:

 ./configure --prefix=/path/to/toy/php

Now we're all set and we can compile the code and install it to the related location:

make install

The make step builds the binaries and the make install step moves them to the correct location - so you may need to sudo make install if your user doesn't have write permission to the location you set in the prefix earlier on.

You're basically done :) Check everything is working by doing:

 /path/to/toy/php/bin/php -v

This should show you what version of PHP you just built.

Checking Your Application With Your New PHP Version

Whatever you have in place for your usual test/build process, you can go through and have it use your /path/to/toy/php/bin/php everywhere it would usually run a php command. This can mean fiddling with environment variables or hardcoding paths in places while you try this out - so if you modify your tools make sure you're making those changes on a branch in your source control tool.

To test out your code with the webserver, you just need to start it using the new PHP version. For me, that command looks like this:

 /path/to/toy/php/bin/php -S localhost:8080

I am seeing more PHP projects being upgraded now, where once they would have been shipped onto a set version, deployed to the server, and left there until they needed replacing. Now we build applications, not just websites, and those need to grow and live along with the companies they exist to serve. The much smoother upgrade process in PHP as well as tools like the webserver make upgrading platforms a perfectly advisable thing to do and I hope the outline above helps someone to make that leap!

The Web Dev Zone is brought to you in partnership with Mendix.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


Published at DZone with permission of Lorna Mitchell , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}