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.
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.
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.
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.
Install at least PHP-FPM for each: apt-get install php5.6-fpm php7.0-fpm php7.2-fpm.
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.
In your <VirtualHost> configuration, use fcgi proxy to run PHP scripts using the FPM pool, e.g.
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.
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.
To avoid to install and configure two or more web server (listeing on two or more ports), try to read these:
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:
For CLI, we can use the command as:
Moving From php7.0 to php5.6
For Apache, we can use the command as:
For CLI, we can use the command as:
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.
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.Install at least PHP-FPM for each:
apt-get install php5.6-fpm php7.0-fpm php7.2-fpm
.Each PHP-FPM comes with a default pool
[www]
configured in/etc/php/x.y/fpm/pool.d
wherex.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.In your
<VirtualHost>
configuration, use fcgi proxy to run PHP scripts using the FPM pool, e.g.Change between PHP versions by using different socket (
php7.0-fpm.sock
,php7.2-fpm.sock
) in theSetHandler
directive above. Reload Apache's configuration after changes.