How to install and configure LEMP on Debian 12

In this tutorial you see the steps you have to travel to install and configure LEP on Debian 12. Ningb, Mariadb and PHP are the software packages needed for performed web hosting, whether it is presentation websites, blogs or online stores.

LEMP is the acronym for Linux, Nginx, MySQL/Mariadb, PHP, and is the basis for many web projects and web applications around the world. Alongu, you could not see this article if behind stealthsetots.com would not be all these packages to ensure the online operation of our website.

Debian is an Open-Source operating system based on Linux, famous for its stability, security and flexibility. With a long history and an active community of developers, Debian offers a wide range of software packages and bookstores to meet the various needs of users. This operating system is commonly used to create reliable and efficient servers for companies, but can also be adapted to personal use.

How to install and configure LEMP on Debian 12

The first step you need to take before installing and setting up LEP on Debian 12, is to connect to the server via SSH (or directly from the console if you have local access). Make sure that there are already installed LEMP packages or administration systems such as: CPanel, Vestacp or others.

The set of commands in this tutorial begins with "sudo"But if you are connected to the server with the user"root", It is not necessary"sudo"In front of the command line. The command"sudo"It is used in front of the command lines to temporarily grant superutizing permissions to a regular user, allowing them to perform orders that require special privileges or access to protected resources, such as installation or configuration of software, system administration or other sensitive operations.

Update Software.

Before starting the installation of LAMP, it is recommended to be updated both the operating system and the already installed software packages.

sudo apt update
sudo apt upgrade

If there are packages available for update, press "Y"When you are asked:

Do you want to continue? [Y/n] Y

Installation and Setup Ningin Web Server on Debian 12

In order for the web server to be able to serve visitors' web pages, Nginx Web Server must be installed and configured correctly.

sudo apt install nginx

Type ”Y"To confirm the installation of NGINX Web Server.

Do you want to continue? [Y/n] Y
Install Nginx Web Server on Debian 12
Install Nginx Web Server on Debian 12

Lines at the end of the installation process, lines must look as follows:

Setting up nginx-common (1.22.1-9) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Setting up nginx (1.22.1-9) ...
Upgrading binary: nginx.
Processing triggers for man-db (2.11.2-2) ...

At the end, to make sure everything works properly, go to the address IP in a web browser. http://your_server_ip.

Welcome to NGINX Page
Welcome to NGINX Page

The NGINX service is functional on your server and is ready to serve web pages.

Related:

Installation and Setup Mariadb Server on Debian 12

Mariadb offers improved performance, higher replication speeds, increased security measures and additional storage engines compared to MySQL.

Execute the command line below and type ”Y"To confirm the installation MariaDB Server.

sudo apt install mariadb-server

After installation, you need to secure the Mariadb Server by running the script: mysql_secure_installation. It will restrict access to the server will eliminate unused accounts.

Execute the command line:

sudo mysql_secure_installation

Press ”Enter"For the current password of the user"root“.

How to install and configure LEMP on Debian 12
Secure SQL #1
Switch to unix_socket authentication [Y/n] Y

Sets password for MariaDB:

Change the root password? [Y/n] Y     
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

Next you will delete privileges and databases set up default during installation MariaDB Server.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Password set above for account ”root"It is necessary when you authenticate on the server from a distance. Remote. This is the password for MariaDB.

Test SQL server installation.

root@mars:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.11.3-MariaDB-1 Debian 12

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select version();
+-------------------+
| version()         |
+-------------------+
| 10.11.3-MariaDB-1 |
+-------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> quit
Bye
root@mars:~# 

Installation and Setup PHP / PHP-FPM on Debian 12

If it all worked well until this step, to install and configure LEP on Debian 12, PHP software is also needed. For PHP support at NGINX you need to install PHP-FPM.

sudo apt install php-fpm php-mysql php-gd php-cli php-curl php-mbstring php-zip php-opcache php-xml

Wait until the installation process is completed PHP-FPM, together with the most important PHP modules.

In the end, in my tutorial I managed to install PHP 8.2 on the operating system Debian 12.

root@mars:~# php -v
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
root@mars:~# 

At this time all the elements in LEP have been installed, but you still need to configure Nginx to execute PHP files.

NGINX configuration to execute PHP files

To configure Nginx for the "Default" page, edit "/etc/nginx/sites-enabled/default". I prefer"nano"For editing.

Replaces in "location /"The line:

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
     }

With the line:

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

Next, add the lines below to the block ”server"To allow Nginx to process PHP.

location ~ \.php$ {
     include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/var/run/php/php-fpm.sock;
     }
}
How to install and configure LEMP on Debian 12
How to install and configure LEMP on Debian 12

Save the file and check the configuration:

root@mars:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@mars:~# 

If the configuration test has succeeded, restart the service nginx.

sudo systemctl restart nginx

Test if you have managed to install and configure LEMP on Debian 12

After installing and configured NGINX, Mariadb and PHP on Debian 12 (LEP), it's time to test if everything works. To test, the simplest is to create an info.php file.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Access in the browser ”https://your_server_ip/info.php“.

PHP Version Info
PHP Version Info

The PHP page means you have succeeded in successfully installing LEMP for Debian 12.

Congratulations!

Passionate about technology, I write with pleasure on stealthsetts.com starting with 2006. I have a rich experience in operating systems: Macos, Windows and Linux, but also in programming languages ​​and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, Presashop).

Home » Your source of IT tutorials, useful tips and news. » How to install and configure LEMP on Debian 12
Leave a Comment