Derick Rethans' Blog<b>Multiple PHP versions set-up</b><br><a href="https://derickrethans.nl/multiple-php-version-setup.html" rel="nofollow noopener" target="_blank">Original Post</a><br><br><p>For many of my projects (both <a href="http://derickrethans.nl/projects.html" rel="nofollow noopener" target="_blank">hobby</a> and <a href="http://derickrethans.nl/who.html#derickrethansltd" rel="nofollow noopener" target="_blank">commercial</a>) 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.</p><p>The major part of it is that I use a different installation prefix for every configuration of PHP that I make. Right now, <code>ls /usr/local/php</code> shows:</p><pre>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</pre><p>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).</p><p>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 :-)</p><p>The scripts accept arguments in a specific order:</p><pre>version ["debug"|"nodebug" [, "no-zts"|"zts" [, ""|"32bit" ] ] ]</pre><p>For a simple 5.3dev build I run:</p><pre>./build 5.3dev</pre><p>This compiles PHP 5.3 from SVN, in debug mode, without ZTS and for the 64-bit architecture. Something more exotic variants could be:</p><pre>./build 5.3.8 debug zts
./build 5.4dev nodebug no-zts 32bit</pre><p>Each invocation of the script will configure and build PHP, and then install into <code>/usr/local/php/{{variant}}</code>.</p><p>The script also has a hard coded location where the PHP sources are. In my case, that's a <a href="https://wiki.php.net/vcs/svnfaq#sparse_directory_checkout_instructions" rel="nofollow noopener" target="_blank">sparse checkout</a> into <code>/home/derick/dev/php/php-src</code>.</p><p>With the help of a small <code>.bashrc</code> snippet:</p><pre>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
}</pre><p>I can now easily switch between PHP versions by typing on the shell:</p><pre>pe 5.3dev</pre><p>or:</p><pre>pe 5.4dev-zts</pre><p>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 <code>php.ini</code> file (in <code>/usr/local/php/{{variant}}/lib/php.ini</code>).</p><p>This set-up makes my life a whole lot easier, and I hope it is useful for you as well. Thanks for listening!</p>