There are few major PHP versions out there such as PHP 5.6, PHP 7.2, PHP 7.4, PHP 8.0 and PHP 8.1. We should always try to use latest version of the software, sometimes we have to stick with an older version due to compatibility issues with the application we are running. If you’re in a such situation, this post will show you how to use multiple PHP versions with Virtualmin and Nginx server.
Why use multiple PHP versions with Virtualmin and Nginx?
I was in a such situation recently. I wanted to have WordPress and CPVLab installed on the same VPS. WordPress is compatible with PHP 7.2 but CPVLab isn’t. Only version of PHP CPVLab supported was PHP 5.6. While I could have both WordPress and CPVLab installed with PHP 5.6, that isn’t an optimal solution. So, I decided to install PHP 7.2 for WordPress and PHP 5.6 for CPVLab.
While my reason to use multiple PHP versions with Virtualmin and Nginx only involves PHP 5.6 and PHP 7.2, I’ll list instructions for all major PHP versions mentioned earlier. These are the PHP versions with ongoing support at the moment of writing.
And before we begin, I’m going to assume you have built your Ubuntu 20.04 server with Virtualmin and Nginx and have created at least one virtual server to host a website.
Add Ondřej Surý Repo to the server
Ubuntu 20.04 doesn’t offer newer versions of PHP than PHP v7.4 yet. We can get around this by adding ondrej/php PPA to the server. No matter which PHP version you’re planning to install, you should start by adding ondrej/php PPA to be able to use multiple PHP versions with Virtualmin and Nginx.
Update apt cache
Server is now ready to have multiple versions of PHP running at the same time. Let’s start with PHP 5.6. Note that Virtualmin, by default use latest version of PHP available on the server for new virtual servers. This can be changed within the virtual server settings itself after creation or you can specify a default PHP version for new servers from Virtualmin settings. More on that later on this tutorial.
Install PHP 5.6 and PHP v8.0 with Virtualmin and Nginx
apt install php5.6-memcache php5.6-imagick php5.6-redis php5.6-bcmath php5.6-intl php5.6-mcrypt php5.6-cgi php5.6-fpm php5.6-mysql php5.6-curl php5.6-gd php5.6-imap php5.6-tidy php5.6-xmlrpc php5.6-xml php5.6-xsl php5.6-mbstring php5.6-zip php5.6-cli php5.6-soap php5.6-gmp php5.6-sqlite3
Install PHP 7.0 and PHP v8.0 with Virtualmin and Nginx
apt install php7.0-memcache php7.0-imagick php7.0-redis php7.0-bcmath php7.0-intl php7.0-mcrypt php7.0-cgi php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-imap php7.0-tidy php7.0-xmlrpc php7.0-xml php7.0-xsl php7.0-mbstring php7.0-zip php7.0-cli php7.0-soap php7.0-gmp php7.0-sqlite3
Install PHP 7.1 and PHP v8.0 with Virtualmin and Nginx
apt install php7.1-memcache php7.1-imagick php7.1-redis php7.1-bcmath php7.1-intl php7.1-mcrypt php7.1-cgi php7.1-fpm php7.1-mysql php7.1-curl php7.1-gd php7.1-imap php7.1-tidy php7.1-xmlrpc php7.1-xml php7.1-xsl php7.1-mbstring php7.1-zip php7.1-cli php7.1-soap php7.1-gmp php7.1-sqlite3
Install PHP 7.2 and PHP v8.0 with Virtualmin and Nginx
apt install php7.2-memcache php7.2-imagick php7.2-redis php7.2-bcmath php7.2-intl php7.2-mcrypt php7.2-cgi php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-imap php7.2-tidy php7.2-xmlrpc php7.2-xml php7.2-xsl php7.2-mbstring php7.2-zip php7.2-cli php7.2-soap php7.2-gmp php7.2-sqlite3
Install PHP 7.3 and PHP v8.0 with Virtualmin and Nginx
apt install php7.3-memcache php7.3-imagick php7.3-redis php7.3-bcmath php7.3-intl php7.3-mcrypt php7.3-cgi php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-imap php7.3-tidy php7.3-xmlrpc php7.3-xml php7.3-xsl php7.3-mbstring php7.3-zip php7.3-cli php7.3-soap php7.3-gmp php7.3-sqlite3
Install PHP 7.4 and PHP v8.0 with Virtualmin and Nginx
apt install php7.4-memcache php7.4-imagick php7.4-redis php7.4-bcmath php7.4-intl php7.4-mcrypt php7.4-cgi php7.4-fpm php7.4-mysql php7.4-curl php7.4-gd php7.4-imap php7.4-tidy php7.4-xmlrpc php7.4-xml php7.4-xsl php7.4-mbstring php7.4-zip php7.4-cli php7.4-soap php7.4-gmp php7.4-sqlite3
Install PHP 8.1 and PHP v8.0 with Virtualmin and Nginx
apt install php8.1-memcache php8.1-imagick php8.1-redis php8.1-bcmath php8.1-intl php8.1-mcrypt php8.1-cgi php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-imap php8.1-tidy php8.1-xmlrpc php8.1-xml php8.1-xsl php8.1-mbstring php8.1-zip php8.1-cli php8.1-soap php8.1-gmp php8.1-sqlite3You can run one or more of above commands and have one or more extra PHP versions running on your server. If you run all commands above, you’ll have all major versions of PHP available to you on the server.
Configure Virtualmin to use a Specific PHP Version
Virtualmin will use latest available version of PHP for new virtual servers. Old virtual servers will not be affected by above commands. If you need a different version of PHP for existing virtual server, you can go to Virtualmin > Domain Name > Server Configuration > PHP Version and select the PHP version you want from the list.
And if you want to change default PHP version for new virtual servers to anything than the latest version available on the server, you can change it from Virtualmin > System Settings > Server Templates > Default Settings > PHP Options. A drop-down list of available PHP versions will be shown to you.
Select the version you want and click save. Selected PHP version will be used for all newly created servers. Option to change PHP version from virtual server settings will also be available to all newly created servers.
Set Default PHP Version for Command Line
update-alternatives --list phpFollowing command should change default php version to PHP 7.1.
update-alternatives --set php /usr/bin/php7.1Change the path to PHP as your software demands.
I have followed your tutorial and everything thing went very nicely but I get a 404 page on every website that I have tried. Only the index.php page works, I get 404 on every other pages except for the administrator directory in a Joomla installation. In that case the administration worsk fine
Lots of search on Google abut well known problem but couldn’t find the solution to it.
I was wandering if you have any idea on how to fix that.
Operating system Ubuntu Linux 16.04.5
Perl version 5.022001
Path to Perl /usr/bin/perl
BIND version 9.10
Postfix version 3.1.0
Mail injection command /usr/lib/sendmail -t
Webalizer version 2.23-08
Logrotate version 3.8.7
MySQL version 10.0.36-MariaDB-0ubuntu0.16.04.1
ProFTPD version 1.35
SpamAssassin version 3.4.2
ClamAV version 0.100.2
Try adding following code,
After fastcgi_param HTTPS $https;
Great article! thanks for help
How do I install version 5.4.16?
It’s no longer supported.
Hey, thanks for the turorial. Can I use this for Virtualmin and Aapche?
Yes, I should work.