To run a website on your Ubuntu 18.04 VPS, you need to install a group of open source software including Apache, PHP, and MySQL. These applications are very useful in running server-side dynamic websites based on databases and scripting languages.

Apache is a fast, secure and consistently high-quality web server software that has been the most popular since 1996.

PHP (Hypertext Preprocessor) is a server-side scripting language designed for web developments.

In this guide, I’ll show you how to install Apache, MySQL, and PHP on Ubuntu 18.04.


  • An Ubuntu 18.04 VPS.
  • Access to root user (can be a non-root user)

Non-root user must have access to sudo

Step 1: Install Apache

Ubuntu 18.04 maintains a central repository where you can install most applications using the apt command. To install Apache, execute the command below:

apt-get install apache2

Press Y when prompted to confirm the installation of Apache. Once the installation is complete, enter the public IP address of your VPS on your browser. The default Apache web page should be viewed as shown below:

Step 2: Install MySQL

In order to install MySQL server on your Ubuntu 18.04 VPS, run the command below on the terminal window:

apt-get install mysql-server

Securing your MySQL server

MySQl server ships with non-secure default settings. We need to configure it to make our server less vulnerable to attack. Fortunately, there is a single configuration command that will make things easier for us. Just execute the command below:


You’re going to be taken through a series of questions. The prompts will enable us to set a password policy and root password. We will also be prompted to delete anonymous user, test database, and disable remote login as shown below.

Step 3: Install PHP

Enter the following command to install PHP on your Ubuntu 18.04 server

apt-get install php libapache2-mod-php

Press Y when you are prompted to confirm the installation

Testing PHP

You can test your installation of PHP by creating a file on your website’s root folder. Type the command below to do this:

nano /var/www/html/info.php

Then copy the text below and click CTR+X and Y to save the file.


Restart Apache

For the changes to take effect, we need to restart Apache using the command below:

systemctl restart apache2

Next, use the public IP address of your server to visit the php info file we created above on your browser. For example, if your IP address is, enter the text below on your browser.


You will be able see the information file for PHP as shown below:


These are the basic steps of installing Apache, MySQL, and PHP on your server. Now you can go ahead and install a user interface for your database (e.g. phpMyAdmin) for the better management of your databases.

Hope you’re successful in this installation. Feel free to ask me any questions in the comment box and I will try to answer them all.