How to install LEMP on Ubuntu 16.04

LAMP (Linux, Apache, MySQL, PHP) is a combination of open source software, usually installed on a server, used to host dynamic websites and web applications.

It includes the Linux operating system, the Apache web server, MySQL for storing data management and PHP for handling dynamic content.

In this article, we will walk through a complete LAMP installation based on an Ubuntu 16.04 VPS.

Requirements

SSH access with superuser privileges to your server as well as Ubuntu 16.04 VPS to be able to complete all the steps in this guide.

1. System update

Before we get started, let’s make sure your system is up to date by running the following command:

apt-get update && apt-get upgrade

Always keep your system up to date. In addition, you can configure automatic updates.

2. Installing Apache

We’ll start by installing the Apache web server. Apache is considered the most widely used web server software. It’s fast, secure, reliable and can be easily customized based on your needs.

To install Apache on the server, run the following command:

apt-get install apache2

After the installation is complete, you must let Apache start automatically at system boot. You can do this with the following command:

systemctl enable apache2

To make sure Apache is running, open a web browser and enter the server’s IP address (for example, http://111.222.333.444). If Apache is successfully installed, you will see a message saying “It works!”

2. Installing MySQL

Next, we will install MySQL on your server. MySQL is one of the most popular database management systems.

To install MySQL on your system, enter the following command and enter Y to continue:

apt-get install mysql-server

During installation, you will be prompted for the password for the MySQL root user. Make sure you enter a strong password.

After the installation is complete, in order to increase the security of your MySQL server, we recommend that you make a secure installation of MySQL by entering the following command:

mysql_secure_installation

First, you will be asked about configuring the password verification plugin.

Would you like to setup VALIDATE PASSWORD plugin?(Press y|Y for Yes, any other key for No) :

This plugin checks password strength and only allows users to set passwords that are secure enough.

Whether it is enabled or not is entirely up to you, but it is always recommended to use strong passwords.

If you choose “Yes”, you will be prompted to select a password verification policy level:

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

Next, you will be prompted to change the password, but since we already created it during the MySQL installation, we can skip this step by pressing Enter.

You will then receive a couple more questions and it is recommended that you answer “Yes” to all of them:

Remove anonymous users? (Press y|Y for Yes, any other key for No) :

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

Again, we can enable MySQL to start at boot with the following command:

systemctl enable mysql

With this, your MySQL installation is complete.

4. Install PHP

The last step in this article is to install PHP. PHP is a programming language mainly used to develop dynamic websites.

We will also include some additional modules to help PHP connect to our Apache and MySQL.

To do this, enter the following command:

apt-get install php7.0 libapache2-mod-php7.0 php7.0-mysql

We can now test if PHP is working correctly by placing a file called info.php in the root of your web server directory.

To do this, enter the following command:

nano /var/www/html/info.php

Enter the following details inside the file and save it:

<?php
phpinfo();
?>

Finally, restart the Apache server by typing:

systemctl restart apache2

Now if you go to this page: http // your_server_ip_address / info.php in your web browser, you will see the following page showing your current PHP configuration:

This means PHP is working as expected. Alternatively, you can install phpmyadmin. This will allow you to manage your MySQL databases through your web browser. You can check the phpmyadmin installation article to see how you can install it on an Ubuntu 16.04 VPS.

With this, you have finished installing LAMP on your system.

Sidebar