Multiple PHP version on Virtualmin in Ubuntu 16.04

Reading Time: 3 minutes

Today, let us try to install multiple PHP version based on your needs. In my case, I will install 5.6, 7.0, 7.2, 7.3 Virtualmin in Ubuntu 16.04. By default, Virtualmin installs PHP 7.0.33 on my Droplet, see the screenshot below:

image-41-1024x241 Multiple PHP version on Virtualmin in Ubuntu 16.04
The following PHP versions are available : 7.0.33 (/usr/bin/php-cgi7.0)

Let us get started!

Install the PPA.

add-apt-repository ppa:ondrej/php && apt-get update

returns:

[email protected]:~# add-apt-repository ppa:ondrej/php && apt-get update

Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advise to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see 
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmpucb8ek3e/secring.gpg' created
gpg: keyring `/tmp/tmpucb8ek3e/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpucb8ek3e/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
Hit:1 http://mirrors.digitalocean.com/ubuntu xenial InRelease
Hit:2 http://mirrors.digitalocean.com/ubuntu xenial-updates InRelease                            
Hit:3 http://mirrors.digitalocean.com/ubuntu xenial-backports InRelease                          
Hit:4 https://repos.insights.digitalocean.com/apt/do-agent main InRelease                        
Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]                      
Get:6 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]                       
Hit:7 http://archive.ubuntu.com/ubuntu xenial InRelease                                          
Hit:8 http://software.virtualmin.com/vm/6/gpl/apt virtualmin-xenial InRelease                    
Hit:9 http://software.virtualmin.com/vm/6/gpl/apt virtualmin-universal InRelease                 
Get:10 http://ppa.launchpad.net/ondrej/php/ubuntu xenial/main amd64 Packages [52.3 kB]           
Get:11 http://ppa.launchpad.net/ondrej/php/ubuntu xenial/main Translation-en [28.2 kB]
Fetched 213 kB in 1s (112 kB/s)                     
Reading package lists... Done

If successfully, let us start with PHP 7.3 installation.

PHP installation.

apt-get install php7.3 php7.3-mysql php7.3-cgi php7.3-cli -y

Once you have completed the installation, you can verify that Virtualmin sees it by logging into Virtualmin, and clicking System Settings -> Re-Check Config. You should see something like this:

The following PHP versions are available : 7.0.33 (/usr/bin/php-cgi7.0), 7.3.6 (/usr/bin/php-cgi7.3)

You can configure which one is the default PHP version used on new Virtual Servers. The default is to use the newest available. You can change that default in System Settings -> Server Templates -> Default -> PHP Options, and on that screen you can set the default PHP version to use in the field Default PHP version.

Finally, if you wish to install your desired PHP version, change the 7.3 to your desired version instead. For example, if you wish to install the 5.6, run:

apt-get install php5.6 php5.6-mysql php5.6-cgi php5.6-cli -y

Configuring Individual Virtual Servers.

You can configure the PHP version being used for a specific Virtual Server by selecting Server Configuration -> PHP Versions.

For example:

image-42-1024x629 Multiple PHP version on Virtualmin in Ubuntu 16.04

At this point, you should be all set.

Source:
Multiple PHP Versions

Was this post helpful?

Leave a Reply