LAMP Stack is a group of very popular open-source software, that when used together enable us to host dynamic websites and web apps. LAMP is actually an acronym that stands for:
Linux – in this case, it is our Ubuntu 18.04 machine
Apache – the most popular web server, that will serve content to our visitors
MySQL/MariaDB – one of the most popular database management systems which will allow to manage and store our data in databases
PHP – the popular and powerful server scripting language that will dynamically process our pages

In this tutorial we’ll install LAMP Stack on an Ubuntu 18.04 machine.


Update your package index to make sure we have access to the latest software releases:

Step 1 – Install Apache

After you run the command, apt will show you what packages it will install, how much disk space it they’ll take up, and ask you to confirm. To proceed, type Y and press Enter.

With Apache2 is installed, you can use the following commands to stop, start and enable the Apache2 service to always start up when the server boots.

You can also check if Apache is up and running on your machine by visiting your server’s IP address in your browser ( example: http://XX.XXX.XX.XX ).

You should be seeing Apache’s default page on Ubuntu:


Step 2 – Install MySQL/MariaDB

You can opt to install MariaDB instead of MySQL, and after you can follow the same instructions as you would with MySQL.

After running the command to install MySQL or MariaDB, apt will show you again what packages it will need to install, how much disk space they’ll take up, and ask you to confirm. Type Y and press Enter to confirm and continue with the installation.

MySQL comes with a script that helps in securing the installation by removing some dangerous defaults. To start the script, run the following command:

First, it will ask you if you’d like to enable VALIDATE PASSWORD PLUGIN.

If you enable this, then depending on the type of validation you choose (LOW, MEDIUM or STRONG), MySQL will return errors if your password does not meet the specified criteria for the policy you’ve chosen. This may conflict with other software packages, so it is up to you to decide. In our tutorial, we will choose Y.

We’ll choose 1. We recommend you choose what level of complexity you prefer between MEDIUM and STRONG.

New password: Enter password
Re-enter new password: Repeat password

You’ll also be prompted to answer some questions to remove/keep some defaults. We recommend you answer them as follows:

Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

To make sure MySQL is properly installed, let’s test it out by running the following command, and entering the password you just created at the prompt:

To exit just run:

Step 3 – Install PHP

Ubuntu 18.04 comes with the latest PHP installed, which is version 7.2. You can install PHP, the Apache PHP module, and a few other PHP related modules by running the following commands:

Test the PHP version:

php -v
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Now that all the PHP packages are installed, restart Apache to make sure the changes are implemented:

To check that PHP is up and running with Apache, you can create a simple PHP file in the Apache2 root directory, which is /var/www/html/.

To create this file run the following commands:

$ sudo nano /var/www/html/phpinfo.php

And add the following line to the file:

Save the file and exit the editor when you’re finished.

Now visit http://your_ip/phpinfo.php, and you should see the default PHP test page:



Congratulations. If everything went well then you’ve successfully installed LAMP Stack on your Ubuntu 18.04 machine.

If you’re ready to host your app and need a high performance budget server, then check out our Linux KVM VPS. They start at 2GB RAM & 10GB SSD at only $5.99/mo.


Tech Support

Leave a Comment


Enter your email below to get 20% OFF on any of our Linux VPS plans and receive weekly deals on our services!