David Hunter

Host a Website using Linux Apache MySQL and PHP (LAMP) on Ubuntu 20.04 LTS

Make sure your virtual machine is powered on and has a fresh install of Ubuntu 20.04 LTS installed.

SERVER TERMINAL

Access your server's terminal using Secure Shell (SSH) with your server's IP Address or the provided web terminal if there is one.

INSTALLING SYSTEM UPDATES

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 hit enter.

Wait for this process to complete, and then reboot your server.

sudo reboot

It may take a moment or two for the server to complete a boot cycle, reconnect after this has been done and proceed.

INSTALLING THE WEB SERVER (APACHE)

To install Apache, enter the following command.

sudo apt install apache2

Confirm by typing Y and hitting 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.

For those that just want a purely static website using HTML CSS and JavaScript, then your server is now ready. Wanting PHP and MySQL, then let's proceed.

INSTALLING THE DATABASE SERVER (MYSQL)

To install MySQL, enter the following command.

sudo apt install mysql-server

Confirm by typing Y and hitting enter. MySQL will now be installed.

MySQL requires additional installation steps.

sudo mysql_secure_installation

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.

sudo mysql

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.

INSTALLING PHP

Type the following command and hit enter.

sudo apt install php libapache2-mod-php php-mysql

Confirm by typing Y and hitting enter.

To see if PHP installed correctly, type php -v to view the PHP version.

CONCLUSION

Well done! You have now installed a fully operational web server to host your website or web app on.