How to install LEMP Stack on Debian 10

LEMP stack is Linux, Nginx, MySQL, PHP. I am assuming you already have Linux, so let’s start by installing Nginx.

1. Nginx Web Server Installation

Nginx is a lightweight, fast reverse proxy server with modular architecture. To install it open up your terminal and run the command below.

sudo apt update
sudo apt install nginx

This will install the Nginx server on your machine. Now lets start the service by running these two commands.

systemctl start nginx
systemctl status nginx

The last line will show the status of the Nginx server if it is active or not. There are three other actions that you can use(restart, stop, and reload). At this point, you’ll have your web server installed and running. You can check by visiting If the service is up, you should see Nginx welcome page. Now let’s move on to the next step.

2. MySQL Database Installation

We are going to install MariaDB as a replacement for MySQL. To install it, run the command below.

sudo apt install mariadb-server

Now, lets start the database server and check the status using following commands.

systemctl start mariadb
systemctl status mariadb

If the database server is installed and running, it will show as an active service after running the second command.

To make the server secure run the command below.

sudo mysql_secure_installation

This will walk you through the installation process of MariaDB.Pr

Hit ‘return’ when it asks for a password for the root user and then you can select ‘Yes/Y’ for the rest of the prompts.

3. Installation of PHP-FPM(PHP Fast Process Manager)

Generally, web servers like Nginx do not have native support for PHP. Therefore, it is required that we install PHP-FPM to handle PHP requests. To install the package, run the following commands.

sudo apt install php-fpm php-mysqli

and then start the server by running the command below

systemctl start php-fpm
systemctl status php-fpm

If you get any error, try php7.3-fpm(replace 7.3 with your version).

4. Configuring PHP-FPM with Nginx

At first, let’s make the PHP-FPM secure by blocking non-PHP files. run the command below.

sudo gedit /etc/php/7.3/fpm/php.ini

You can replace ‘gedit’ with your favorite editor. find the line ;cgi.fix_pathinfo=1, uncomment it and change the value to 0.


PHP-FPM listens to Unix Socket, by default. To use this to server PHP files, paste this line below in your terminal and hit enter.

sudo gedit /etc/nginx/sites-available/default 

Look for a section like this

#location ~ \.php$ {
            #include snippets/fastcgi-php.conf;
            # With php-fpm (or other unix sockets):
            #fastcgi_pass unix:/run/php/php7.3-fpm.sock;

            # With php-cgi (or other tcp sockets):
            #fastcgi_pass 127.0.01:9000;

Now, change it to the code block below.

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

Save the file and run following command to verify configuration is okay.

sudo nginx -t

Now, go to ‘/var/www/html’ and create a PHP file and check. If you have followed along, you should have a web server running successfully.

Leave a Reply