Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
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

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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