How to Install Nginx, MariaDB & PHP (LEMP) on Debian 10

Updated on February 8, 2022
How to Install Nginx, MariaDB & PHP (LEMP) on Debian 10 header image


The LEMP stack consists of Linux, Nginx, MySQL, and PHP. It is similar to the LAMP stack, but instead of using the Apache web server, it uses Nginx instead. There are many benefits to using Nginx including performance, and security improvements.


1. Install the Packages

Install Nginx, MariaDB, PHP, and the PHP package for MySQL.

$ sudo apt install nginx mariadb-server php-fpm php-mysql python3-certbot-nginx

2. Configure Nginx

Open the configuration file. Replace with your domain name.

$ sudo nano /etc/nginx/sites-available/

Add the following configuration. Save, then exit. Replace with your domain name.

server {
        listen 80;
        listen [::]:80;


        root /var/www/html;
        index index.html index.htm index.php;

        location / {
                try_files $uri $uri/ =404;

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

Enable the configuration.

$ sudo ln -sf /etc/nginx/sites-{available,enabled}/

Remove the default website configuration.

$ sudo rm /etc/nginx/sites-enabled/default

Reload Nginx so it will see the new configuration.

$ sudo systemctl reload nginx

Obtain an SSL certificate through Certbot, this will enable HTTPS on the domain. Replace with your domain name, and with your email address.

$ sudo certbot -d -m --agree-tos --noninteractive --nginx --redirect

3. Configure MariaDB

Run the MariaDB installation script.

$ mysql_secure_installation

Press enter when prompted for the current root password.

Enter current password for root (enter for none):

Specify "n" to not set a root password on the database.

Set root password? [Y/n] n

Press enter to disable anonymous users.

Remove anonymous users? [Y/n]

Press enter to disable root logins from remote machines.

Disallow root login remotely? [Y/n]

Press enter to remove the test database.

Remove test database and access to it? [Y/n]

Press enter to reload the privilege tables that store the database's users and permissions.

Reload privilege tables now? [Y/n]

4. Test the Server

Create a PHP test script.

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

Save the following code and exit.


Open in your browser. Replace with your domain name.

You should see a screen listing the version of PHP and other information. If so, you can remove the test script.

$ sudo rm -f /var/www/html/test.php