Multiple PHP Versions - My Experience
Multiple PHP Versions - My Experience
As I have recently had issues running multiple versions of PHP with Virtualmin on Ubuntu 16LTS, and there were posts related to such a configuration - I thought I'd post some discoveries.
Before you read on, I would like to note;
A) I am not a Virtualmin employee, nor am I affiliated with Virtualmin in any other way than using their products.
B) The notes below are of my experiences in getting things up and running. They are not intended to be taken as gospel.
C) Though the steps below may be trivial to some users, they do have the potential to break your environment entirely. Backup before you do anything in production, or as always; TEST IN A DEVELOPMENT ENVIRONMENT FIRST.
Most importantly: If you have any suggestions on improving setup, I highly encourage you to post a reply!
Issue 1 - Ubuntu Package Manager (aptitude) Meta Packages
Changing php versions, if possible, gave some odd errors or would sometimes break configuration entirely.
This issue was hard to investigate. Though I had all the php versions required installed, I found that the php meta package was conflicting (Resulting in almost 2 copies of php5.6 conflicting). It's not clear in the documentation that I read. For those whom do not know what the php meta package is; it's simply a pointer to the most appropriate/default version of php to install (Which I believe, currently; is php5.6).
Ensure you install php by version, including modules.
Remove meta package
apt-get remove php
Install version specifics
apt-get install php5.6-fpm php5.6-cgi php5.6-fcgi php7.0-fpm php7.0-cgi php7.0-fcgi php7.1-fpm php7.1-cgi php7.1-fcgi
Additionally, when installing php module packages - ensure you pick version specific - and consider removing any that may appear to be meta.
apt-get install php5.6-xml php5.6-mysql php7.0-xml php7.0-mysql php7.1-xml php7.1mysql - etc.
Note: Some packages are unavoidable in meta. This is just the way the package maintainer has released them. Examples, I have installed in my current environment without immediate issues, are; php-common, php-dompdf, php-font-lib.
Issue 2 - Ubuntu Package Manager (aptitude) Auto Configuration
Changing php versions in Virtualmin, though set in configuration, does not actually apply to the website. (You can test this by dropping a file in your host with 'php_info();')
Ubuntu's package manager will configure/enable the apache modules for your php versions related packages at a core apache level upon install - especially for the meta package. This does not seem to apply to 'additional' modules, such as php5.6-xml - in which, after installation; you're prompted to use a2enmod then restart the apache service.
Ensure that your root apache configuration is not loading certain php versions by default.
You can confirm this with;
ls /etc/apache2/mods-enabled | grep -i php
If you have results, these versions are enabled by default. As these results are symlinked from the /etc/apache2/mods-available/ directory - it IS safe to delete them. Remove the linked files invoking specific php configurations;
rm /etc/apache2/mods-enabled/php-fpm for example - fpm, fcgi, cgi, mod_php related modules in this directory.
Issue 3 - Ubuntu Package Manager (aptitude) Library and Module Conflicts (Not entirely clear as to why this happened)
Apache does not start due to issues with invalid versions of libraries or modules related to php extensions. (Sorry - I do not have a copy of the error - but starting the service will output that lib .so files versions are mismatched)
I'm not entirely sure as to why this happened. I believe it's a combination of the messy system, and packages, I had in result to investigating and trying to fix / resolving the above errors. Basically; I had to install the mod-php libraries for apache2.
apt-get install libapache2-mod-php5.6 libapache2-mod-php7.0 libapache2-mod-php7.1
If you were impacted with any of the issues mentioned in this; you should now be able to switch php versions without error. Note; php*-fpm seems to still be a bit weird at times, depending on the site. fcgi and cgi work without fault.
Note: Edited for readability after submission returned unexpected issues.