1 C
Texas
angeloma
Senior Writer and partner

How to install LEMP server on Debian 9?

Many web developers prefer Nginx to Apache. Actually, Nginx has a better performance but a slightly more delicate configuration than Apache. So today I’ll show you how to install the LEMP server on Debian 9.

You probably know that LAMP (Linux, Apache, MySQL /MariaDB, and PHP) is a basic stack for setting up a functional web server. With this server, you can start developing applications or simply run them.

The problem is that many prefer Nginx to Apache. This may be because of their wide performance gap, or simply a matter of necessity. The detail is that simple, we are going to install a LAMP server but with Nginx. That’s why it’s LEMP.

So, let’s install LEMP on Debian.

Install Nginx

- Advertisement -

The first step to install LEMP is to install the first of its components (apart from Linux, obviously) and that is Nginx. You can do this from the official Debian repositories. However, before to install it, I recommend upgrading the system.

:~$ sud
:~# apt update && apt upgrade

1.- Upgrading the system
1.- Upgrading the system

Next, install Nginx.

:~# apt install nginx

2.- Install Nginx
2.- Install Nginx

Then, enable and start the service.

:~# systemctl enable nginx
:~# systemctl start nginx

3.- Enabling and starting the Nginx service
3.- Enabling and starting the Nginx service

In case you have ufw enabled, you need to run this command.

:~# ufw allow 'Nginx HTTP'

Now, it is done.

Install MariaDB

The second step is to install and configure MariaDB. MariaDB is a popular database manager among developers. It is also available in the official Debian repositories.

You just need to type:

:~$ apt install mariadb-server

4.- Installing MariaDB
4.- Installing MariaDB

Then, enable and start the MariaDB service.

:~# systemctl start mariadb
:~# systemctl enable mariadb

systemctl start mariadb systemctl enable mariadb
5.- Enabling MariaDB service

Next, set a root password using the mysql_secure_installation script.

:~$ mysql_secure_installation

6.- Using the mysql_secure_installtioin script
6.- Using the mysql_secure_installtioin script

In this script, several questions will be asked. You can answer as you want since the configuration depends on each user, in my case, I have answered Y, N, Y, Y.

Install and configure PHP

Now, you need to install PHP to run the web applications. It is simple to do it.

:~# apt install php7.0-fpm php7.0-mysql

7.- Installing php
7.- Installing PHP

Next, you need to tell Nginx to use PHP. To do it, you need to edit the Nginx default site configuration file.

:~# nano /etc/nginx/sites-available/default

Leave it as I show it in the image.

8.- Enabling PHP support on Nginx
8.- Enabling PHP support on Nginx

Then, create a .PHP file to verify that everything is in order.

:~$ echo "<?php phpinfo(); ?>" > /var/www/html/index.php

9.- Creating a sample PHP file
9.- Creating a sample PHP file

Finally, open your web browser and go to HTTP://IP_SERVER/index.php

10.- PHP running
10.- PHP running

Now, you know how to install LEMP on Debian 9.

Conclusion

As you can see, it is not so complicated to install LEMP on your server with Debian 9. On the contrary, it is something simple that won’t take you long.

Please share this file with your friends.

- 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