DebianLinuxTutorials

How To Install LEMP Stack on Debian 10

Install LEMP Stack on Debian 10

In this tutorial, we will show you how to install LEMP Stack on Debian 10. For those of you who didn’t know, LEMP is an acronym for Linux, Nginx, MySQL/MariaDB, and PHP. Linux is the server operating system. Nginx (which is pronounced as Engine-X, hence the letter E in the acronym) is the web-server software.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the LEMP on a Debian 10 (Buster).

Prerequisites

  • A server running one of the following operating systems: Debian 10 (Buster).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install LEMP Stack on Debian 10 Buster

Step 1. Before running the tutorial below, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update

Step 2. Installing Nginx on Debian 10.

Nginx is an open-source and cross-platform, lightweight yet powerful, and easy to configure HTTP and reverse proxy server. Run the following command to install it:

sudo apt install nginx

After it’s installed, Nginx should be automatically started. Check its status with systemctl:

sudo systemctl status nginx

Next, if you have the UFW firewall running (it is usually disabled by default), you need to open ports 80 (HTTP) and 443 (HTTPS) to allow incoming traffic on Nginx:

sudo ufw allow 80
sudo ufw allow 443

Now type in the public IP address of your Debian 10 server in the browser address bar. You should see the default “Welcome to Nginx” Web page, which means the Nginx Web server is running properly.

http://your-server-ip-address

Install LEMP Stack on Debian 10

Step 3. Installing MariaDB on Debian 10.

MariaDB is the default database system in Debian 10. To install MariaDB, run the following command:

sudo apt install mariadb-server

MariaDB service should be up and running at this moment. Check the status of the MariaDB service using the below command:

sudo systemctl status mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MariaDB database):

mysql -u root -p

Step 4. Installing PHP on Debian 10.

Install the PHP FastCGI Processing Manager, which includes the core PHP dependencies:

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

Now start php-fpm and enable auto-start at boot time:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Step 5. Configure Nginx to work with PHP.

Now we create a brand new server block file under /etc/nginx/conf.d/ directory with a command-line text editor:

sudo nano /etc/nginx/conf.d/default.conf

Add the following file:

server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

  location / {
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

Once done, apply the recently made changes, restart the php-fpm and Nginx services as follows:

sudo nginx -t
sudo systemctl reload nginx

Step 5. Test PHP.

To test PHP, create a test file named info.php with the content below. Save the file, then browse to it to see if PHP is working:

sudo nano /usr/share/nginx/html/info.php

Paste the following PHP code into the file:

<?php
phpinfo();
?>

Now head over to the browser and browse the info.php file as shown http://your-server-ip-address/info.php. If the PHP info page is rendered in your browser then everything looks good and you are ready to proceed further.

Congratulations! You have successfully installed LEMP. Thanks for using this tutorial for installing the latest version of LEMP Stack on the Debian system. For additional help or useful information, we recommend you check the official LEMP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button