Ubuntu 18.04 ships with slightly newer versions of software including Nginx 1.18 and PHP 7.3. But in this tutorial, we will be setting up PHP v7.4 as the default version of PHP for websites with ability to have all major PHP versions. This can be easily done thanks to Virtualmin.
We’re dropping MariaDB as it has many incompatibles with our setup. It’s simply not worth the time to make it work at this time. So let’s get started. First step is obviously get a VPS that can house Virtualmin and all other software. We recommend a 2GB RAM server as the minimum and 4GB RAM server for best performance. But please note that amount of server resource you will need depend on your website. Please head over to our recommended unmanaged VPS providers list and get a server with Ubuntu 18.04 as the operating system. Once you have root access to the server, you’re ready to install Virtualmin with nginx on Ubuntu 18.04.
I’m going to assume you already know how to login to your VPS using SSH. Let’s start by setting up a proper hostname for your Ubuntu 18.04 VPS. With that completed, let’s move on to building the server.
Add Ondřej Surý Repo to Ubuntu 18.04 Server
Ubuntu 18.04 comes with PHP v7.2. 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 compatible version of PHP for our setup. 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 we 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 on Ubuntu 18.04 Server
We will be using the bash script provided by Virtualmin developers for the installation. It’s the easiest way to install Virtualmin. Following command will fetch the bash script to your server.
The script will try to install Apache2 as the webserver. So we will manipulate the install command to skip that and tell Virtualmin to build our server with Nginx instead.
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.18, PHP v7.2 and MySQL v5.7 on the server. 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 PHP v7.4 and Additional Modules on Ubuntu 18.04 server
apt install php-pear php-imagick 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-xsl php7.4-mbstring php7.4-zip php7.4-cliNow 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.4Above command sets PHP v7.4 as the default PHP version for command line.
Secure MySQL Installation on Ubuntu 18.04 server
mysql_secure_installationMy input for the first question is a No and Yes to everything else.
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.
This concludes Virtualmin and LEMP installation for now. But there are few more things you need to do to make sure your server has optimal configuration to host websites. I’ll guide you through them on Virtualmin Post-Installation Configuration and Server Optimization tutorial.