I'm a currently learning how to work with freebsd. Lately I have been trying to run multiple php versions along with their respective packages. However, I seem to be running into issues while making installations.

The default location for my php installation is /usr/local/etc/, however I want to be able to install php5.2, php5.3 and php5.4 in /usr/local/etc/php52, /usr/local/etc/php53 and /usr/local/etc/php54 respectively.

Using ports I simply achieved this by doing cd /usr/ports/lang/php5x && make PREFIX="/usr/local/etc/php5x" install clean.

The problem now is: How do I do the same for extensions of all my PHP versions? When I try installing php-extensions like so: cd /usr/ports/lang/php5x-extension && make PREFIX="/usr/local/etc/php5x/lib/php" install clean, I get this error

===>  PHPizing for php53-bcmath-5.3.17
env: /usr/local/bin/phpize: No such file or directory
*** Error code 127

Stop in /usr/ports/math/php53-bcmath.
*** Error code 1

Stop in /usr/ports/lang/php53-extensions.

My PHPize is located in /usr/local/etc/php5x/bin/phpize So how do I get make or whatever to look for phpize in the right path? Is there a cleaner, may be simpler way of maintaining multiple php installations? I need to achieve this because of compatibility issues from some legacy code that runs on 5.2 and breaks on 5.3.

Thank you.

  • 2
    Did you consider just setup up multiple machines in jails? – Hennes Nov 20 '12 at 18:41
  • 1
    Why do you want to do this? There's really no good reason for this configuration that I can think of. It CAN be done, but for your own safety I'm not going to tell you how unless you can convince me you're well aware of how big a foot-gun this is and are not going to be aiming it at your own feet (or mine) :-) – voretaq7 Nov 20 '12 at 18:55
  • @Henne, Nope, but probably will now. What are the advantages of setting up machines in jail over having muliple PHP installations? Thank you – jgtumusiime Nov 20 '12 at 19:35
  • 1
  • 2
    I think that it makes sense to ask this as a new question. Because if you completely edit your original post then answers (like the one voretaq7 gave) no longer match with the question. Generally some editing is fine, but if you want to change completely from 'How do I install multiple PHP versions?' to 'How do I manage jails?' then it is too much of a change for the same question. – Hennes Nov 21 '12 at 17:23

The variable noone talked about is called PHPBASE: It allows working with multiple PHP installs on a FreeBSD server, placing each in it's own directory. It's then used in make.conf to point specific PHP modules (php52-somethings vs. php54-somethings) at the right "base" directory.

I've seen it used a few times, but didn't dare try it myself, so far.

When I looked for the an example for you I now actually found a apparently better example...

Look here:


In case someone (still) wonders why one would do this:

The key is socalled seamless upgrades. It's something you do if you need to run servers for actual users and not just in your own basement. If you give users a quick path of upgrading and are able to switch forth/back between versions, they can eventually migrate. Otherwise they will eventually migrate too, not to the PHP version you give them, but to a different provider.

  • Good follow up. :) – Hennes Apr 5 '15 at 23:30

Your best bet would be as Hennes suggests: Create a jail for each version of Apache+PHP you want to use. This has a number of advantages, the two biggest ones being isolation (if your PHP 5.2 sites get hacked the damage is contained to the PHP 5.2 Jail) and management simplicity (treat the jails like they're two separate FreeBSD installations -- one running old PHP, one running new PHP -- and you don't have to jump through any hoops).

In addition to the handbook section I linked above you may want to consider some of the jail management ports available. ezjail is pretty well regarded and there are some nice tutorials on using it, but there are many others -- search for jail in the ports tree and you'll find them.

The big downside to jails is you'll be running a discrete Apache for each version of PHP you want to run (which means, essentially, one IP address per jail). If you only have one IP and are doing name-based virtual hosting there are some hacks you can do (haproxy or similar, and rerouting to a different back-end based on hostnames), but they're all ugly in their own way.

The other option (the huge foot-gun I referred to in my comment) is to compile PHP as you've been doing with a non-standard PREFIX, and then to manually install each extension - tweaking your path, linking the phpize binary to the expected location, or doing a full manual build.

I've maintained systems this way in the past (due to my heavily customized PHP requirements), but never with multiple versions. You will also need to maintain separate apache instances (each loading the appropriate PHP version), which won't work if you use name-based virtual hosting (similar to jails).

With the non-jailed approach you also have the option of hacking things so Apache loads multiple versions of the PHP interpreter (or running PHP as a CGI) which is more friendly for name-based virtual hosts. You just have to take care to set it so the right version of PHP gets called for each location / file type. If you mess it up "Strange Things" start happening (or, if you're lucky, it just breaks horribly and you don't spend hours debugging it).

Given the two choices Jails are a far superior option - expect to burn a little more disk space, but disk is cheap and the added isolation and ease of maintenance is almost certainly worth it if you can't upgrade the PHP 5.2 code to play nice on a more recent version.


If you still want to go along and install multiple versions of PHP. You can easily do it with PHP + fast-cgi. You can wrap this around with PHP-FPM or mod_fcgid to make dispatching to the right PHP version easy. Here is a good tutorial on Installing multiple versions. Use a website or Application’s vhost-config (apache) to choose which PHP it should run.

This is how you should go about installation of PHP versions of freebsd: Install a base PHP version from ports e.g PHP52, then install PHP53, PHP54 from source. Installing multiple versions from ports might cause conflicts. Or you could just install all PHP versions from source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.