Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to have both PHP 5.2.17 and PHP 5.3.5 installed on my Ubuntu machine and switch as per my necessity. How can I achieve this?

share|improve this question
    
in ubuntu there is apache.conf in /etc/apache2, i thought about this too, maybe i will in the future make some package it would be very useful for web developers –  user22472 Jul 29 '11 at 21:00
    
You can do this with suPHP, not sure the details –  Marco Ceppi Jul 29 '11 at 21:32
1  
is there somthing like python virtualenv to have clean isolated deployments of PHP ? –  lenzai Feb 20 '12 at 2:01
    
Have you considered setting up virtual Ubuntu servers using virtualisation software that you use in a headless fashion? I'd be surprised if what you are wanting to do is not well served (no pun intended) by such a set-up. –  Simon Hoare Feb 1 '13 at 13:32
    
Define what it means to "switch easily". I used this for work: my webserver was using different PHP for .php and .php5 files. You can also configure your WWW server to use different PHP versions for different ports (like http://localhost:80 and http://localhost:8080) or different domains (like http://localphp52 and http://localphp53) leaving all the remaining structure of folders intact so you can easily compare running one web application in two environments by changing the current URL. –  Cyprian Guerra Feb 3 '13 at 1:10

5 Answers 5

You can use a php version manager to achieve this. Different version managers are available like:

My favorite is phpbrew. Hope this helps.

share|improve this answer
    
Thanks,Can you please include instructions? (onnu vishadheekarikkamo?) –  Tachyons Feb 3 '13 at 9:14
3  
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Nanne Feb 3 '13 at 11:02
    
Just check the links they have really good documentation on their sites. Do you really want me to copy-paste things from their website?. –  aneeshep Feb 3 '13 at 12:14
1  
Ironically, one of the reasons not to just post links is linkrot, from which this post now suffers. –  MirroredFate Aug 15 '13 at 15:49

You can run 2 different PHP versions at once, but it's not as easy as just apt-getting them. You need to run one seperately installed version and serve it up according to the settings in your apache config.

You can do this using fastcgi for example: basically what you are looking for is the config you see on this page. You add a different handler in your config based on the situation/port/domain you need. The trick, after installing both versions, is this step:

===from that page==

  1. The last step was to create virtual hosts. In the end I have three files in /etc/apache2/sites-enabled: 000-default, php5.3.17 and php5.4.7 With the following contents

default:

    <VirtualHost *:80>
      ServerName localhost
      DocumentRoot /var/www
      <Directory "/var/www">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        AddHandler php-cgi .php
        Action php-cgi /php-fcgi/php5317.fcgi
      </Directory>
    </VirtualHost>

php5.3.17:

    <VirtualHost *:80>
      ServerName 5317.localhost
      DocumentRoot /var/www
      <Directory "/var/www">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        AddHandler php-cgi .php
        Action php-cgi /php-fcgi/php5317.fcgi
      </Directory>
    </VirtualHost>

php5.4.7:

    <VirtualHost *:80>
      ServerName 547.localhost
      DocumentRoot /var/www
      <Directory "/var/www">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        AddHandler php-cgi .php
        Action php-cgi /php-fcgi/php547.fcgi
      </Directory>
    </VirtualHost>

See for the complete installation the linked question. Don't forget to look at the two links in the header as well, they look like nice tutorials (but less compressed). This and That

(don't be put of by the fact that the linked question is a big one with no accepted answer. The method should (and does) work fine, but the user forgot to use <?php and used <? with shorttags off, see the comments)

share|improve this answer

Problems:

a) Single apache instance can not run two different PHP versions simultaneously (at least as far as I know it).

b) Two different PHP versions can't be installed from packages as those will conflict (and try overwriting the same directories).

Solution:

for b) Compile „the other” PHP version from source, manually (or if you prefer, grab source of appropriate package and modify it to avoid conflicts and to modify install paths)

for a) Create separate set of configs for apache with different module paths and separate startup script. And of course run it on separate port.

share|improve this answer
    
there is no prepackaged script to compile these multiple parallele php instance ? Just to do it manually and patch paths ? SO this means that all hosting company develop there custom scripts to run these parallel version and never share their effort. –  lenzai May 25 '12 at 12:56
    
A single apache instance can run 2 php versions at once. –  Nanne Feb 1 '13 at 10:46

I guess that will do what you need!

You can also run each website with diferentes users. More secure.

I used this aproach one time.

http://blog.servergrove.com/2011/08/22/how-to-setup-multiple-php-versions-on-apache/

Now i think it is better to use php-fpm... but it is a litle more complicated to configure multiple php versions.

Will need to run multiples php-fpms and set apache to use each other.

I hope this helps!

share|improve this answer
1  
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  user98085 Feb 2 '13 at 23:40
    
I did not have time enough to do as you said. I guess, i only wanted to show a way. Stil need to learn how to use the formating stuff. Thanks anyway! –  Henrique Fernandes Feb 14 '13 at 15:24

If you want to run them at the same time, you need two different ports. Maybe you can just change your apache config (httpd.conf) with a simple script that moves one or another version into the correct position before starting apache.

share|improve this answer
1  
I already have PHP 5.3.5 installed. How can I install PHP 5.2.17? Could you please tell me where and what I have to change to switch between in these two versions? The httpd.conf file is empty in my installation. –  Debiprasad Jun 24 '11 at 12:18

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.