Menu

Gray Matter @ rtcx.net

Close

LEMP on an Ubuntu Server and an Ubuntu Desktop

RT Cunningham | June 10, 2021 (UTC) | Linux, Web Development

LEMPLEMP is an acronym that stands for Linux, Nginx (engine-x), MySQL or MariaDB, and PHP. It’s a variation of LAMP, with the “A” standing for Apache web server. This stack of software is commonly called a “LEMP stack”.

Although I mentioned Ubuntu in the title, the instructions will work for any Debian or Ubuntu based Linux distributions. In fact, I’ve used them on Ubuntu Server 20.04 and Linux Mint 20, my preferred distributions.

LEMP Tutorials

I have two sources for installing the software. DigitalOcean has a good tutorial for installing LEMP on Ubuntu Server 20.04. TechyFingers has a good tutorial for installing LEMP on Ubuntu Desktop 20.04 or any Debian or Ubuntu derivative that uses the APT package manager. I recommend saving those web pages to your computer, especially the TechyFingers page, if you need to do it all again someday.

Although the instructions are usually only good for these specific versions, the next versions will probably work much the same.

Web Server Instructions

Nginx lives at “/etc/nginx”. The files you want to edit are “/etc/nginx/nginx.conf” and “/etc/nginx/sites-available/default”. While some examples will show you how to create multiple “sites-available” files for Nginx server blocks, it’s much easier to use the default file alone. This is especially true if you’re only dealing with one website or web application.

Your default servers (virtual hosts) should look like this to block attempts to servers that don’t exist. You probably won’t need the second section on your local machine:

server {
        listen              80 default_server;
        server_name         _;
        root                /var/www/html;
        access_log          off;
        error_log           /dev/null;
}
server {
        listen              443 ssl http2 default_server;
        server_name         _;
        root                /var/www/html;
        access_log          off;
        error_log           /dev/null;
}

Database Instructions

Whether you choose to use MySQL, MariaDB or even Percona Server for MySQL, I can’t improve on the instructions given elsewhere. There is one thing, though, that I want to mention.

A lot of people install PHPMyAdmin to work with databases. Others use Adminer. The thing they forget to do is remove the application when it’s no longer needed. Why else would both of them be popular attack vectors? Installing either application is easy. Remove it, and any server blocks you create for it, when you’re done. It serves no purpose when it’s not being used anyway.

PHP Instructions

Installing PHP is straightforward, and the tutorials explain it well enough. No one seems to mention, however, that you can use “php -m” in the terminal to list all the modules installed with it. Websites for applications that rely on PHP usually mention which PHP modules are required, but not always.

Although you can install PHP itself with your LEMP stack, it’s PHP-FPM that works with Nginx. Make sure you edit the correct PHP.INI file.

Image Attribution: lewing@isc.tamu.edu Larry Ewing and The GIMP / CC0

Share: Facebook | Twitter

These Posts May Also Be Interesting:


Gray Matter @ rtcx.net
Copyright © 2020, 2021
RT Cunningham

Blogroll and Other Links: