
The LEMP stack (Linux, Nginx, MySQL/MariaDB, and PHP) is a free, open-source web application stack used to develop and deploy web applications. The LEMP Stack is like the LAMP stack, but it substitutes Nginx for Apache web server. This guide explains how to install a LEMP stack on Debian 11 and use Certbot to secure it with a Let's Encrypt TLS/SSL certificate.
This guide assumes you want to use both the apex domain example.com and the www.example.com hostname for your server. To follow this guide, you should assign both the apex domain (sometimes referred to as @) and the www hostname to the server's IP address in your DNS settings.
Install the Nginx web server.
Start the Nginx service.
Enable the Nginx service to start at system reboot.
Check the Nginx version to verify the installation.
You should see output like this:
List the available application profiles.
Among the other entries, you should see the following profiles:
Allow the Nginx Full profile in the firewall. Certbot requires ports 80 and 443 to install a Let's Encrypt TLS/SSL certificate.
Check the Firewall status.
You should see output like this:
Remove the default Nginx configuration.
Create an Nginx virtual host configuration file. Replace your-domain-name.com with your domain name.
Paste this into the file. Replace example.com with your domain name.
Enable the new Nginx configuration. Replace example.com with your domain name.
Reload the Nginx service.
Install MariaDB database server.
Start the MariaDB service.
Enable the MariaDB service to start at system reboot.
MariaDB provides a security script to secure the database. Run it and answer all the security questions as shown.
Initially, there is no password for root. Press Enter.
Press Y to Switch to unix_socket authentication.
Press Y to change the root password.
Press Y to remove anonymous users.
Press Y to remove remote root login.
Press Y to remove test database and access to it.
Press Y to reload the privilege tables.
Connect to the MariaDB shell and enter your MariaDB root password.
Check the MariaDB version to verify the installation.
It should return something like this:
Exit MariaDB shell.
Install PHP-FPM 7.4 and other required packages.
Check the PHP version to verify the installation.
It should return something like this:
Create a PHP test file in your editor.
Paste this into your phpinfo.php file.
Save and exit the file.
In your browser, navigate to http://www.example.com/phpinfo.php to view the PHP test file, which shows the PHP information.
Certbot requires Snap. Install snapd and enable classic Snap support.
Either log out and back in again, or restart your system, to update Snap’s paths.
Install the core Snap to get the latest snapd.
Update core Snap.
Verify there are no Certbot packages installed with apt.
Install Certbot with Snap.
Link Certbot to /usr/bin.
Request a certificate for your server. Replace the example email and domains your values. The command shown requests a multi-domain (SAN) certificate for example.com and www.example.com.
Test your SSL configuration on an SSL check website like SSL Labs.
Navigate to your website and verify the SSL certificate works as expected.
This completes the initial setup of your LEMP server. The server is ready for you to install applications that work with LEMP, or develop your own.
0 Comments
Be the first to comment and share your perspective with the community.