22.9 C
Texas
angeloma
Senior Writer and partner

How to install LEMP on Debian 10 Buster?

Debian is such a stable system that many people use it as an operating system for servers. These servers deploy a lot of different network services. However, we can also have a light web server using LEMP. LEMP is another software stack quite popular with web developers. So, in this post, you will learn how to install LEMP on Debian 10.

LEMP Components

LEMP is a stack of software that together makeup what is necessary to establish a web server. First of all, a Linux (L) distribution is required, in this case, the one chosen is Debian 10 because it is quite stable. In addition, Debian 10 has just been released and therefore presents us with many new security features.

Then comes an HTTP server. If it were apache then, we would talk about LAMP, but in this case, it is Nginx (E). A lighter and more functional server. You could say it’s high performance.

Applications process data, that is, they require a database handler to create a database. The other component of LEMP is MariaDB (M).

- Advertisement -

In order to process the applications made, a programming language is required. For the web, the most popular is PHP (P).

Now, we can start to install LEMP on Debian 10.

Install LEMP on Debian 10

1) Install Debian

Logically, first, we must install Debian 10. For that, we have a post where we explain it in detail.

Read how to install Debian 10 Buster?

Then, after installing we can continue with the installation.

2) Install Nginx webserver

Nginx is an open-source web server quite popular in the web world. This is because it is a lightweight server, powerful and able to process many requests without consuming so many resources. On the other hand, Nginx has a free version that is quite good. It is easy to install and well documented.

So, open a terminal or connect to your server and run:

:~$ sudo apt install nginx

Note: If you do not have sudo enabled, read this post.

Then, you can open your web browser and go to http://your-server-IP. You will see this:

1.- Install LEMP on Debian - Nginx default page
1.- Install LEMP on Debian – Nginx default page

So, Nginx is running properly.

3) Install PHP and configure PHP to work with Nginx

After this, it is necessary to install PHP. So you have to install it along with several of its modules. These modules are required by certain applications.

:~$ sudo apt install php php-cli php-xml php-mbstring php-mysql php7.3-fpm

2.- Install PHP to getting LAMP on Debian 10
2.- Install PHP to getting LAMP on Debian 10

Then, some settings need to be changed so that Nginx can work with PHP. The first thing to do is to edit the file that handles the virtual servers. We will use the default as the basis for editing.

:~$ sudo nano /etc/nginx/sites-available/default

image

In this fairly simple file, we explain where the root document is that is /var/www/html. In the index line, add index.php and it will look like this:

index index.php index.html index.htm index.nginx-debian.html;

Then, in the location ~.php$ section leave it this way:

location ~ \.php$ {
 include snippets/fastcgi-php.conf;

 # With php-fpm (or other unix sockets):
 fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
 # With php-cgi (or other tcp sockets):
 # fastcgi_pass 127.0.0.1:9000;
 }

3.- configuring PHP to work with Nginx
3.- configuring PHP to work with Nginx

Then, press CTRL + O to save the changes and CTRL + X to close it.

After that, set a new value for cgi.fix_pathinfo parameter on/etc/php/7.3/fpm/php.ini

:~$ sudo nano /etc/php/7.3/fpm/php.ini
cgi.fix_pathinfo=0

Again, CTRL + O to save the changes and CTRL + X to close the file.

Now, you have to reload PHP-fpm and Nginx service.

:~$ sudo systemctl reload nginx
:~$ sudo systemctl reload php7.3-fpm

Now, in order to test PHP create a new file called test.php on /var/www/html with the following content.

:~$ sudo nano /var/www/html/test.php
<?php
phpinfo();
?>

And open it using the web browser.

4.- PHP working with Nginx
4.- PHP working with Nginx

Now, you have Nginx and PHP working.

Last step to Install LEMP on Debian 10: MariaDB

Finally, it is necessary to install MariaDB. To do this, run the following command:

:~$ sudo apt install mariadb-server

5.- Install MariaDB
5.- Install MariaDB

After installing MariaDB, you need to define a root password and secure the installation. This can be done using the mysql_secure_installation script. So run it.

:~$ sudo mysql_secure_installation

There you will be asked about some configurations.

Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database and access to it? Y
Reload privilege tables now? Y

6.- Using mysql_secure_installation
6.- Using mysql_secure_installation

And that is it.

Conclusion

Having a web server is easy using Linux. To do this, just install LEMP on Debian 10. This way you will have a robust, secure and above all open source web server. Able to process persistent data without sacrificing computer resources.

Please share this post with your friends and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article