dedicated PHP version per virtual host
Solution 1
actually I found a working solition w/o need for .htaccess. Check for How to Install Multiple PHP Version with Apache on Ubuntu 18.04 & 16.04 - https://tecadmin.net/install-multiple-php-version-apache-ubuntu/
Thanks to Rahul Kumar.
Solution 2
You can't do this with mod_php, it can only load one version at a time.
You can run multiple FPM instances on different versions, or use PHP via FCGI (howtos for each are kicking around on the net), but you'll lose the mod_php integrations (like php_flag and php_value in configs) that you may require.
You can mix and match, too - so have one version in mod_php and others in FCGI or FPM; I've previously had the 'known good' version in mod_php while testing under FCGI, then upgraded the mod_php version when I'm ready.
Alternatively, you could run two Apache installs with a different mod_php in each, but that might get more messy (and they can't share a socket).
The modern way of doing this is to use a VM or a container for your testing.
Related videos on Youtube
Thomas-AC
Updated on September 18, 2022Comments
-
Thomas-AC over 1 year
I have an Ubuntu 18.04 LTS Server with PHP7.2 and PHP5.6 installed. Two Virtual Hosts so far are configured alike:
<VirtualHost *:80> # domain: php56.test # public: /var/www/php56/ ServerName php56.test ServerAdmin webmaster@localhost DocumentRoot /var/www/php56 <Directory /var/www/php56/> Require all granted Options Indexes FollowSymLinks MultiViews AllowOverride None </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Now I want to dedicate PHP5.6 to php56.test and PHP7.2 to php72.test.
I played around the .conf files according several articles on the web, but could not succeed. Either I could get run PHP5.6 or PHP7.2, but not both at a time as required for the dedicated sites. Default .conf as is and site related alike above php56.test.conf.
-
kukulo over 5 yearsI would check these answers here: stackoverflow.com/questions/42696856/…
-
Thomas-AC over 5 yearsHi Nisse, well I tried this and also other approaches w/o succes. I guess, I might not know nevcessary relationship among the virtual host at sites-available, conf-available and .htaccess, or I am holding wrong content in one of these files. Permissions supposely should be ok.
-
-
Thomas-AC over 5 yearsHi BigRedS, I am using Oracle VM. The point is, I need to have it switchable per site e.g. by .htaccess. the issue with mod_php I was not aware of. I tried with FPM only approaches, but also w/o succes. I guess, I might not know nevcessary relationship among the virtual host at sites-available, conf-available and .htaccess, or I am holding wrong content in one of these files. Permissions supposely should be ok.