Install Virtualmin, Nginx v1.20, PHP v8, MySQL v8 on Ubuntu 20.04 Server

It’s upgrade time for us here at vpsfix.com. Our install Virtualmin with nginx tutorial had been updated with latest Ubuntu versions over the past few years. We’ve tested our Virtualmin-nginx server setup on latest Ubuntu 20.04 LTS distribution and decided it’s time to make the move.

Although we’re updating this tutorial to Ubuntu 20.04 LTS, Ubuntu 18.04 LTS is supported until April 2023. So, there’s no rush if you’re already on Ubuntu 18.04. With that been said, there’s an advantage in upgrading. You get to enjoy the latest software versions. Ubuntu 20.04 comes with MySQL v8, nginx v1.18 and PHP v7.4 as default versions. But we’ll add couple of tweaks to get nginx v1.20 and PHP v8.0 as default versions on Ubuntu 20.04 LTS. Although we can upgrade to these versions manually on previous versions of Ubuntu, it’s not a good idea to do so on production environment.

Prerequisites

I’m using a 4GB RAM server from Vultr for this tutorial as usual. Vultr is ranked #1 on our recommended VPS providers list. Like on our previous tutorials, the server you build following this server setup guide will allow you to have all major PHP versions. First step is to get a VPS with at least 4GB of RAM. I’m going to assume you already have a server. It can be an unmanaged VPS from our list of recommended providers or any provider out there.

Once you have the credentials, you can login to your VPS over SSH. This allows you to execute the commands displayed on this and our many other tutorials.

Next, you need to configure a proper hostname for your server. Doing so will avoid potential hostname resolution errors in the future.

With those two steps completed, you can now move on to installing Virtualmin with nginx on Ubuntu 20.04 LTS.

Add Ondřej Surý Repos to Ubuntu 20.04 Server

We will start the installation by adding Ondřej Surý’s PHP and Nginx repositories to the server. Ondřej Surý is a well-known Debian Developer. Using his repositories will allow you to install the latest versions of PHP on the server or even have multiple PHP versions running at the same time. Following command will add ondrej/php PPA to the system.

add-apt-repository ppa:ondrej/php

Trouble with add-apt-repository?

We will also add ondrej/nginx PPA to the system so we can get the latest nginx version.

add-apt-repository ppa:ondrej/nginx

Update apt cache,

apt update
apt upgrade

Install Virtualmin on Ubuntu 20.04 LTS with Nginx

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.

wget http://software.virtualmin.com/gpl/scripts/install.sh

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.20, PHP v8.1 as the default version and MySQL v8 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.

virtualmin-install-complete

Install PHP v8.0 and Additional Modules on Ubuntu 20.04 server

Your VPS should have all major PHP versions installed by now. But none of them meets the requirements by most PHP applications. We’ll fix this by installing some of the commonly used modules and their dependencies. These include ImageMagick, Memcached and Redis Server and all the PHP modules suggested by WordPress. Following command should take care of that.

apt install imagemagick memcached redis-server php8.0-imagick php8.0-memcache php8.0-redis php8.0-bcmath php8.0-intl php8.0-mcrypt php8.0-cgi php8.0-fpm php8.0-mysql php8.0-curl php8.0-gd php8.0-imap php8.0-tidy php8.0-xmlrpc php8.0-xml php8.0-xsl php8.0-mbstring php8.0-zip php8.0-cli php8.0-soap

Your server should be ready to server most PHP applications without any hiccups by now. Let’s configure the PHP version used by CLI to PHP v8.0 as well.

update-alternatives --set php /usr/bin/php8.0

It may be possible that some of the PHP applications doesn’t support PHP v8.0 yet. Or it simply needs a specific PHP version other than v8.0, you can follow our instructions to install multiple PHP version on the same server to solve that. This will allow you to have older PHP versions like PHP v5.6 or newer PHP versions like PHP v8.1 on your Ubuntu 20.04 server.

Secure MySQL Installation on Ubuntu 20.04 server

MySQL 8 comes with some dangerous default settings. This section only focuses on securing those. There are more to securing a MySQL installation than this. But running this simple command and following on-screen instructions will give you some comfort that your databases are secure.

mysql_secure_installation

You’ll be first asked whether you want to enable VALIDATE PASSWORD plugin for MySQL 8. Enabling this option will cause conflicts with Virtualmin. So, you should opt to disable it here. Press a key other than Y to and then hit Enter to disable it.

Now you’ll be asked to create a password for MySQL root user. Enter a strong password and then you’ll be asked a series of questions. Your response for all these questions should be ‘Yes’. 

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.
https://example.com:10000/

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.

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Related Articles

2 Comments

  1. Hi. Thanks a lot for this tutorial. I just have one question. I got to the page where I need to login to the server (webmin). what needs to be the username? since it was not mentioned in the tutorial or maybe I missed something.
    Thanks In advance.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.