Installing Nginx, MySQL, PHP (LEMP) on Ubuntu 16.04

A virtual private server (VPS) is most often used to host dynamic websites and applications. This requires installing and configuring a web server. The LEMP “stack” involves the Linux operating system (L), the Nginx web server (E), a MySQL database (M), and PHP for dynamic webpages (P).


Before you start, you need the following:
  • A VPS running Ubuntu 16.04
  • A regular (non-root) account with sudo privileges. See our SSH keys tutorial for more information.

Step 1: Disabling apache2

We need to ensure that Apache (a different web server option) isn’t running. Let’s remove it from the server.
sudo apt-get remove apache2
sudo rm /var/www/html/index.html

Step 2: Installing Nginx

Ubuntu’s apt package management software makes installing nginx quite easy. Running the update command ensures you get the most up-to-date version.
sudo apt-get update
sudo apt-get install nginx
Nginx will automatically start running at this point. You can double check this by navigating to the IP address of your VPS via a web browser.
If successful, you’ll see a default Nginx page.

Step 3: Installing MySQL

Next, we’ll install MySQL, which is a database that will be used to store information. Install this with apt as well.
sudo apt-get install mysql-server
You will be prompted to input a password for the adminisrative user for MySQL. We recommend a strong, secure password. For additional security, you won’t be able to see the characters as you type them in. Next, run a script to improve the security of the installation.
sudo mysql_secure_installation
You’ll see the following warning about the VALIDATE PASSWORD PLUGIN .
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: 
This plugin will reject passwords that are not strong enough. It’s not necessary if you’re diligent about using strong, secure passwords. If you choose Yes , you’ll be asked to define a policy for strong passwords. You will also be given an opportunity to change the root password if you’d like.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 
For the remainder of the questions, type in y or Y and then hit Enter.... Read More