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
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
Next, install Nginx.
:~# apt install nginx
Then, enable and start the service.
:~# systemctl enable nginx :~# systemctl start nginx
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
Then, enable and start the MariaDB service.
:~# systemctl start mariadb :~# systemctl enable mariadb
Next, set a root password using the mysql_secure_installation script
.
:~$ mysql_secure_installation
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
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.
Then, create a .PHP file to verify that everything is in order.
:~$ echo "<?php phpinfo(); ?>" > /var/www/html/index.php
Finally, open your web browser and go to HTTP://IP_SERVER/index.php
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.