Make sure your virtual machine is powered on and has a fresh install of Ubuntu 20.04 LTS installed.
Access your server's terminal using Secure Shell (SSH) with your server's IP Address or the provided web terminal if there is one.
Check for updates by executing the following command in the terminal for your server.
sudo apt update
It will show you if any software needs to be upgraded, and if so, the following command will do just that.
sudo apt upgrade
You will be asked if you are happy to proceed, type Y and press enter.
Wait for this process to complete, and then reboot your server.
It may take a moment or two for the server to complete a boot cycle, reconnect after this has been done and proceed.
To install Apache, enter the following command.
sudo apt install apache2
Confirm by typing Y and pressing enter. Apache will now be installed.
Open your web browser (or a new tab if its already open) and go to your server's IP address. If you see the Apache default page, then Apache was successfully installed.
Type the following command and hit enter.
sudo apt install php libapache2-mod-php
Confirm by typing Y and pressing enter.
To see if PHP installed correctly, type php -v to view the PHP version.
You now have a Web Server with PHP. If you do not need a MySQL Database then you can stop here.
To install MySQL, enter the following command.
sudo apt install php-mysql mysql-server
Confirm by typing Y and pressing enter. MySQL will now be installed.
MySQL requires additional installation steps.
Validate Password Plugin: It is recommended to use this to secure your system if used for production purposes. Type Y and enter to enable it.
If you enabled the Validate Password Plugin, you will be presented with a password strength screen. It is recommend to set this to 2 for strong passwords on production servers.
Type a password for the root user of the MySQL database. Make sure it is secure and note it down in a secure place such as a password manager.
If you enabled the Validate Password Plugin, it will calculate the strength of your password. Confirm with Y to continue or anything else to change it.
Lastly, check that MySQL was installed correctly.
It will show a new terminal cursor prefixed with mysql> if it worked. To exit MySQL, type exit and hit enter. You should now be back on the main terminal screen.
Notice you did not need to type in the password to log into MySQL, this is because by default MySQL allows any logged in user with sudo privilages to login as root to the MySQL server. This sounds like a security concern but its actually the opposite. It is recommended you create a new MySQL user to use with your applications. More on this in another tutorial.
Well done! You have now installed a fully operational web server to host your website or web app on.