Skip to the content.

The following tutorial presumes you understand what a LAMP Server is, how to work a website from the back end. It also expect experience running other Basic Terminal Commands.

There is also an excellent article on Digital Ocean that may be of more relevance if you are working on a remote or public facing server.

1. Install Apache

To install Apache you must install the Metapackage apache2. This can be done by searching for and installing in the Software Centre, or by running the following command.

sudo add-apt-repository ppa:ondrej/apache2
sudo apt install apache2

2. Install MySQL

To install MySQL you must install the Metapackage mysql-server. This can be done by searching for and installing in the Software Centre, or by running the following command.

sudo apt install mysql-server

3. Install PHP

PHP requires a few packages to work as you expect, so we recommend the following command.

sudo add-apt-repository ppa:ondrej/php
sudo apt install php php-mysql libapache2-mod-php

4. Restart Apache Server

Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn’t, execute this command:

sudo service apache2 restart

5. Check Apache

Open a web browser and navigate to http://localhost/. You should see a message saying It works!

6. Check PHP

You can check your PHP by executing any PHP file from within /var/www/. Alternatively you can execute the following command, which will make PHP run the code without the need for creating a file .

php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'

7. Secure MySQL

We recommend you run the guided setup for securing MySQL, but this may be unecessary in a development environment.

sudo mysql_secure_installation

Congratulations, you have just Installed a Ubuntu LAMP Server!