Multiple PHP versions set-up
For many of my projects (both hobby and commercial) I need to support many different PHP configurations. Not only just different PHP versions, but also debug builds, ZTS builds and 32-bit builds. In order to be able to test and build extensions against all those different PHP configurations I have adopted a simple method that I'm sharing with you here.
The major part of it is that I use a different installation prefix for every configuration of PHP that I make. Right now, ls /usr/local/php shows:
5.1dev 5.3.2 5.3.8dev 5.3dev-32bit 5.3dev-zts 5.4dev trunk 5.2dev 5.3.7 5.3dev 5.3dev-nodebug 5.4.0beta1 5.4dev-zts
There are two types of PHP installs that I make: "dev" versions from SVN branches, and "release" versions build from SVN tags. From the list above you see I have the SVN versions of 5.1, 5.2, 5.3.8, 5.3 (in various forms) and 5.4 (both normal, and ZTS).
I have a script to compile PHP which whatever combination I want: version, debug (default) or non-debug, normal (default) or ZTS; and 64-bit (default) or 32-bit. The configure options are nicely hardcoded :-)
The scripts accept arguments in a specific order:
version ["debug"|"nodebug" [, "no-zts"|"zts" [, ""|"32bit" ] ] ]
For a simple 5.3dev build I run:
./build 5.3dev
This compiles PHP 5.3 from SVN, in debug mode, without ZTS and for the 64-bit architecture. Something more exotic variants could be:
./build 5.3.8 debug zts ./build 5.4dev nodebug no-zts 32bit
Each invocation of the script will configure and build PHP, and then install into /usr/local/php/{{variant}}.
The script also has a hard coded location where the PHP sources are. In my case, that's a sparse checkout into /home/derick/dev/php/php-src.
With the help of a small .bashrc snippet:
function pe () {
version=$1
shift
if [ "$#" == "0" ]; then
export PATH=/usr/local/php/${version}/bin:/usr/local/bin:/usr/bin:/bin
else
PATH=/usr/local/php/${version}/bin:$PATH $@
fi
}
I can now easily switch between PHP versions by typing on the shell:
pe 5.3dev
or:
pe 5.4dev-zts
And each version will have a totally separated environment for me to install PEAR packages and PECL extensions in, and do my own extension development. Of course, each separated environment also comes with its own php.ini file (in /usr/local/php/{{variant}}/lib/php.ini).
This set-up makes my life a whole lot easier, and I hope it is useful for you as well. Thanks for listening!
Likes
Comments
For people who don't need to switch all the time, but still want a few different builds of php installed, I can recommend GNU Stow which lets me install
/usr/local/stow/php5.3 /usr/local/stow/php5.4-dev
and then creates symlinks like
/usr/local/bin/php -> /usr/local/stow/php5.4-dev/bin/php
Also handy for all kinds of self-compiled tools that would create a mess inside /usr/local...
Something related: https://github.com/CHH/phpenv (port of rbenv, which is nice). Not sure if it supports specifying debug/non-debug or 32bit/64bit though.
What I was thinking yesterday was: setting up also Apache is a bit more difficult, since I'll have to link the right .so and restarting it each time. I also need only to differentiate only between 5.3 and 5.4: that's why I use a virtual machine for running one of them.
How many total different set up versions of Php?
@Burton: At the moment, there are 16. But PHP 5.4RCs are on the way too!
Funny timing. I was in the middle of doing something similar when I came across your post. It gave me some good ideas, thanks. I just pushed it to https://github.com/convissor/php_version_solution.
Gentoo makes this really easy:
Thanks for sharing,
Just wonder why the script is always --enable-debug in $OPTIONS...
Hi, I'm trying to set things up so that users of my upcoming extension have the option of using a precompiled version. Something like these people have: http://www.pdflib.com/?id=744 one download for each os+hardware, containing various compiled files for each flavour of PHP.
Is this at all possible on a single machine? For example would it be possible to extend your system so that I can compile for linux on my mac?
@blog what an old post ;)
BTW still have some value
Notice: I prefer using environment -modules which allow to quickly change used version
module load php8.5
but also to switch back to default
module unload php8.5
And the configuration is really simple
Ex /etc/modulefiles/8.5
%Module1.0
prepend-path PATH /opt/php85/bin
prepend-path LD_LIBRARY_PATH /opt/php85/lib
prepend-path MANPATH /opt/php85/php/man/
Life Line
📷 Stalkers Lane
🚩 Graywood Lane, Wealden, United Kingdom
After my PHP 8.5 in Leeds last night, it's now time to head to Rotterdam to give the same talk there tonight!
It's cold out here, but atleast the snow is now gone.
📷 Avenue Gardens
🚩 Princess Road, London Borough of Brent, United Kingdom
📷 Leafy Entrance
🚩 East Heath Road, London Borough of Camden, United Kingdom
📷 From Green to Yellow.
🚩 St John's Wood Road, City of Westminster, United Kingdom
The Secret Maps exhibition at the British Library is well worth a visit!
We went last Sunday and it still runs to January.
📷 Mirror
🚩 The Terrace, London Borough of Richmond upon Thames, United Kingdom
📷 Green, Red, Orange, and Yellow
🚩 Mortlake High Street, London Borough of Richmond upon Thames, United Kingdom
📷 Leaf
🚩 Lonsdale Road, London Borough of Richmond upon Thames, United Kingdom
I walked 10.6km in 1h47m32s
Merged pull request #1048
Fixed issue #2386: Crashes when running context_get in an exception t…
It's PHP 8.5 release week !
I'm giving two talks on what's new in it, first on Wednesday evening in Leeds: https://www.meetup.com/leedsphp/events/311677834/
And then on Thursday evening in Rotterdam: https://eventy.io/events/q8lmw0v4Will I see you there?
@robinince Loving the new series of the Infinite Monkey Cage so far! #bbc
I walked 1.7km in 18m51s
Updated a clothes shop and a restaurant; Deleted a dentist; Confirmed an estate_agent shop, a dentist, and 2 other objects
I walked 3.4km in 39m19s
I walked 5.7km in 57m30s
📷 Low Thames
🚩 Ranelagh Gardens, London Borough of Hammersmith and Fulham, United Kingdom












Shortlink
This article has a short URL available: https://drck.me/multi-php-8u3