2

Is there an easy way to run multiple versions of PHP on Ubuntu 10.04 (desktop), and switching between them?

I am spoiled with the very easy installation and switching of PHP in WAMP for Windows. This would be for a development environment.

4 Answers 4

2

The idea would be to manually compile several versions of PHP (./configure, ./make but not ./make install), and have the PHP extension you request loaded within your VirtualHost configuration.

That way, you can postpone loading the PHP library until you need it, and you can choose a different PHP library for each VirtualHost.

1
  • More details would be appreciated, especially about the part "have the PHP extension you request loaded within your VirtualHost configuration"! Feb 15, 2013 at 13:53
1

To avoid to install and configure two or more web server (listeing on two or more ports), try to read these:

1

I had the same problem when I was handling multiple projects. I referred this article But it was like every time I need to switch the versions if need but this gives the flexibility for cli and web separately.

Moving From php5.6 to php7.0

For Apache, we can use the command as:

sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart

For CLI, we can use the command as:

sudo update-alternatives --set php /usr/bin/php7.0

Moving From php7.0 to php5.6

For Apache, we can use the command as:

sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

For CLI, we can use the command as:

sudo update-alternatives --set php /usr/bin/php5.6
1
  • You might find my alternative of using PHP FPM handy. See my answer. May 29, 2018 at 6:28
0

Another question with outdated approaches popped to the front page, so let's answer. Nowadays PHP-FPM gives a solution where you can have multiple versions of PHP installed simultaneously. It enables you to switch between the versions without a2enmod / a2dismod and also allows changing this for one project at a time.

Here's an example of a server with PHP 5.6, PHP 7.0 and PHP 7.2 running simultaneously.

  1. This server is Debian 9. Likewise, any distribution may only have packages for one PHP version. I use deb https://packages.sury.org/php/ stretch main in my apt sources.

  2. Install at least PHP-FPM for each: apt-get install php5.6-fpm php7.0-fpm php7.2-fpm.

  3. Each PHP-FPM comes with a default pool [www] configured in /etc/php/x.y/fpm/pool.d where x.y represents the PHP version. In production environments I'd suggest using a new pool for each site (see my answer on securing web server with separate users), but for simplicity I'll use these default pools in this example. It may also be ok in development.

  4. In your <VirtualHost> configuration, use fcgi proxy to run PHP scripts using the FPM pool, e.g.

    <FilesMatch "\.php$">
            SetHandler  "proxy:unix:/run/php/php5.6-fpm.sock|fcgi://localhost"
    </FilesMatch>
    <Proxy "fcgi://localhost/">
    </Proxy>
    
  5. Change between PHP versions by using different socket (php7.0-fpm.sock, php7.2-fpm.sock) in the SetHandler directive above. Reload Apache's configuration after changes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .