Ubuntu 16.04 now ships with Nginx v1.10, PHP v7.0 and MariaDB v10.0.36. I had only got Nginx v1.4.6, PHP v5.6 and MySQL v5.7 with my old Virtualmin-Nginx setup on Ubuntu 14.04 LTS. That right there is a good reason to upgrade. I’ve tested this setup on my server and its working. It’s working great. You’ll clearly see performance improvements of your website.
And I’m sure you all heard about PHP v7.3 and how it’s so much better and faster than previous versions of PHP. Now you can enjoy its benefits on your server. And MySQL is gone. Instead Ubuntu 16.04 comes with MariaDB. But unfortunately Virtualmin still uses MySQL. But don’t worry, we’ll replace MySQL with MariaDB. There are so many good things to say, but I think we should get to the installation.
I’m going to assume that you already have a VPS with root access. If you don’t, you can get one from a unmanaged VPS provider I recommend. Logged in to Ubuntu 16.04 server as root user, run following command to check your server’s hostname.
If the output is anything other than your domain name or a sub-domain, you should change it before you install Virtualmin with nginx. Refer to change Ubuntu 16.04 hostname from command line tutorial and change it now.
Add Ondřej Surý Repo to the serverUbuntu 16.04 comes with PHP v7.0. Which isn’t the latest version of PHP available. For that reason, we’re going to use Ondřej Surý’s PHP repository to get the latest version of PHP. Ondřej Surý is a well known Debian Developer. Using his repositories will allow us to install the latest version of PHP on our system or even have multiple PHP versions running at the same time if need to. Following command will add ondrej/php PPA to the system.
We will also add ondrej/nginx PPA to the system so we can get the latest nginx version.
Update apt cache,
apt update apt upgrade
Install Virtualmin with Nginx
This part is similar on all Linux distributions. Download the Virtualmin installation script to your server,
Run the script to install Virtualmin with nginx.
sh /root/install.sh -b LEMP
You’ll be asked to confirm the action. Confirm it and Virtualmin installation will begin. It’ll take few minutes for the installer to complete. It’ll setup Nginx v1.16, PHP v7.3 and MySQL v5.7. You’ll be asked for permission to a swap file if your server has less than 1GB of RAM. You’ll be greeted with following message on your Putty screen when Installation completed.
Install Additional PHP 7.3 Modules
Due to the ondrej/php PPA we added earlier, Virtualmin script installs all major PHP versions on your server by default. But for this tutorial, we will use PHP v7.3 only. If you need PHP version other than PHP v7.3, you can follow my instructions to use multiple PHP versions on your server. Since PHP v7.3 is already on your VPS, you only need to install few PHP modules on your server for most php applications to work. Following command will install essential PHP v7.3 modules on your server.
apt install memcached php-memcache php-pear php-imagick php7.3-cgi php7.3-mysql php7.3-curl php7.3-gd php7.3-imap php7.3-tidy php7.3-xmlrpc php7.3-xsl php7.3-mbstring php7.3-zip php7.3-cli
Now you need to make sure server is using correct PHP version for the command php. If your php application requires setting up cronjobs, this step is mandatory, or your application will misbehave.
update-alternatives --set php /usr/bin/php7.3
This command sets PHP 7.3 for PHP-CLI.
Replace MySQL with MariaDB
Virtualmin installs MySQL on the server by default. But I like to use MariaDB for my databases. MariaDB is a drop-in replacement for MySQL and is considered as an improved version of MySQL. So let’s remove MySQL. First stop MySQL,
service mysql stop
apt-get remove mysql-server mysql-common
apt-get install mariadb-server
That’s all you have to do to replace MySQL with MariaDB. Now Secure MariaDB.
Securing MariaDB Databases
There is more you can do to secure MariaDB databases. But at this point, running following command will guide you through changing some dangerous default settings. My input for the first question was No and Yes to everything else. It’ll also ask you for a new MariaDB password. You don’t need to change it here just type the same password you set on Virtualmin post-installation wizard.
Complete Virtualmin Post-Installation Wizard
You can access Virtualmin on following URL with your root password. Make sure you replace example.com with your domain name. Your DNS should be propagated for this to work. If DNS isn’t propagated yet, you can replace example.com with your server’s IP address.
You’ll be taken to the Virtualmin Post-Installation Wizard after the login. It is pretty self-explanatory, just remember to select MySQL/MariaDB as database server and Only store hashed passwords as password storing method. You’ll be good with default selections for all other steps.
You’ll be given an option to check Virtualmin configurations after the Post-Installation wizard. Click Recheck and refresh configuration button to check your server for errors. The most common error I’ve encountered was system is not setup to use itself as a DNS server. If everything goes well, you’ll be greeted with .. your system is ready for use by Virtualmin.
Set default PHP version for Virtualmin
The default PHP version configuration for Virtualmin is set to “Highest Available” by default. This is not an ideal setting for us since we’ve configured PHP v7.3 for CLI. you can change this easily from Virtualmin > System Settings > Server Templates > Default Settings > PHP Options. A drop down list of available PHP versions will be shown to you.
Select PHP v7.3 and click save. Now PHP v7.3 will be used for all newly created servers.
That concludes Virtualmin-Nginx installation on Ubuntu 16.04. Your VPS is now fully configured to host websites using Nginx as the web server.