A LEMP Stack is a group of open-source software commonly used for hosting dynamic websites and web apps. LEMP is an acronym for Linux operating system, Nginx [engine x] web server, MySQL (or MariaDB relational database management system) and PHP.

This guide shows you how to install a LEMP stack on a Debian 9.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Note: The user you are logged in as must have sudo privileges to be able to install packages.

Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:

sudo apt-get update && sudo apt-get upgrade

Step 1: Install Nginx

Nginx is available in the Debian repositories by default, hence the installation is quite straightforward. Issue the command below:

sudo apt install nginx


Nginx service will automatically start after the installation process is complete. Issue the command below to check the status of the service.

sudo systemctl status nginx

Step 2: Install MariaDB
The next step is to install the MariaDB packages. MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. Issue the command below to install MariaDB:

sudo apt install mariadb-server


After installation, issue the command below to check the status of our MariaDB installation:

sudo systemctl status mariadb


Our MySQL database is now running so the next thing to do is to run a simple security script that will remove some dangerous defaults and lock down some default access to our database system. Start the script by issuing the command below:

sudo mysql_secure_installation

The script will ask a couple of questions including:

  • Current root password – Since this is a new installation of MySQL, you probably don’t have one so you can leave it blank and you will be asked if you want to set one. Type Y and proceed.
  • Remove anonymous users - Type Y or press the enter button to choose the default (which is Y).
  • Disable root login remotely - Type Y or press the enter button to choose the default (which is Y).
  • Remove test database - Type Y or press the enter button to choose the default (which is Y)
  • Reload privilege tables - Type Y or press the enter button to choose the default (which is Y)



At this point, our database system is now set up and we can move on to the next step in our installation.

Step 3: Install PHP
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. In this case, it will run scripts, connect to our MariaDB databases for information, and deliver processed content over to our web server to display. Debian 9 ships with PHP 7.0. To install PHP and most common PHP modules use the following command:

sudo apt install php-fpm php-opcache php-cli php-gd php-curl php-mysql


After installation of PHP on the server, type the following command in order to see the current release version of PHP.

php -v


Step 4: Configuring Nginx to Process PHP Pages
Next, we need to edit the Nginx virtual host configuration file and add the following lines for Nginx to process PHP files:

server {

# . . . other code

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;