Avatar of tonelm54
tonelm54
 asked on

Install multiple versions of PHP but specify in host config

Ive usually installed PHP via:-
sudo apt install php libapache2-mod-php php-mysql

Open in new window

Which works great and installs the latest version of PHP and configures everything fine :-)

Problem is I want some of my sites to run on PHP 5 (for historical purposes), some to run on the current version of PHP 7 and some to run on a future version of PHP 7 for testing.

On my hosting website, I can add a line into the vhost configuration to tell it what version of PHP to run, for example to run PHP7 I just add this into the htaccess file and it runs the site with PHP 7:-
AddType application/x-httpd-php70 .php
This is exactly what I want to do, however all the guides Ive found online talk about running everything under the same version, but not individual sites.

Anyone got any ideas on this?

Ideally I want to download different versions of PHP into a folder \PHP\PHP7.3\ and then inside htaccess point to use \PHP\PHP7.3\ or something different.

Im using Ubuntu server with Apache if that helps, and this is only for development purposes, not production.
InstallationPHPUbuntuLinuxLinux OS Dev

Avatar of undefined
Last Comment
noci

8/22/2022 - Mon
kenfcamp

You're not going to be able to do this on the same server
Kimputer

In the main configuration, add these:


<Directory "/www/htdocs/site1">
AddType application/x-httpd-php70 .php
</Directory>


<Directory "/www/htdocs/site2">
AddType application/x-httpd-php5 .php
</Directory>

   

ASKER CERTIFIED SOLUTION
Chris Stanyon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
noci

Gentoo allows installing multiple version of the php server by default. Still running multiple on one webserver can be challenge.


Probably switching to php-fpm is an option (fastcgi php) then you can run several instances ( different config or versions ) 

and map certain paths to certain fpm backends.  which is considerable simpler to maintain and manage.

(It also allows for setups like for only one of the paths on your site you need humoungous amount of memory for buffering) then you can use a setup with limited number of backends for that one wile the others have multiple instances running. 

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes