How to Install LEMP Stack on Debian 10 Buster

Install LEMP Stack on Debian 10

In this article, we will have explained the necessary steps to install and setup LEMP Stack on Debian 10. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

A “LEMP” stack is a mixture of open-source software that is typically installed on a Linux server to deploy dynamic applications. This term is an acronym that represents the Linux operating system, Nginx web server, a MariaDB database, and PHP programming.

Install LEMP Stack on Debian 10

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Nginx.

The Nginx package is included in the default Debian Buster repositories. Run following command to install Nginx:

Once it is installed, start and enable the Nginx service by typing:

To verify that the service is running, check its status:

Configure Firewall.

UFW users can open HTTP (80) and HTTPS (443) ports by enabling the ‘Nginx Full’ profile:

Nginx Configuration File’s Structure.

  • Nginx configuration files are stored in the /etc/nginx directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • Server block (vhost) configuration files are stored in /etc/nginx/sites-available directory. The configuration files found in this directory are used by Nginx only when linked to the /etc/nginx/sites-enabled directory.
  • To activate a server blocks create a symlink (a pointer) from the configuration file in a sites-available directory to the sites-enabled directory.
  • To write more maintainable code, it’s a good idea to follow a standard naming convention. For example, if your domain name is mydomain.com then the configuration file should be named /etc/nginx/sites-available/mydomain.com.conf.
  • The /etc/nginx/snippets directory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments then you can refactor those segments into snippets and include the snippet file to the server blocks.
  • Nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have a different access and error log files for each server block.

At this point, you need to test if Nginx is properly installed, whether it is running and can serve web pages. To do that, open a web browser and point it to the following URL to access the Nginx Debian Default web page.

Step 3. Install MariaDB.

First, import MariaDB gpg key and add repository:

Install the MariaDB server and client packages by running the following command:

Now confirm the installation by typing following:

After installing MariaDB in your system start it’s service using the following command:

Secure MariaDB server.

You should now run mysql_secure_installation to configure security for your MariaDB server:

Then enter yes/y to the following security questions:

As a test, you can log into the MariaDB server and run the version command:

Step 4. Install PHP 7.3.

First, add SURY repository:

Next, installing PHP v7.3 with the following command:

Verify the PHP installation, by typing the following command which will print the PHP version:

If you are using Nginx as your web server then just restart the Nginx service using the following command and you are good to go:

Congratulation, you have learned how to install and configure LEMP on Debian 10 Buster. If you have any question, please leave a comment below.