Blog

Tutorials, guides and product news.

Developers

What are LAMP and LEMP stacks?

3 November 2026 5 min read
Share this post

LAMP and LEMP name the four pieces of software that serve a typical website: Linux, a web server, a database and PHP. The A in LAMP stands for Apache, and the E in LEMP stands for Nginx (it is pronounced "engine-x", hence the E). In both stacks the database is MySQL or MariaDB and the programming language is PHP.

PHP applications such as WordPress, WooCommerce and Joomla run on this stack. WordPress.org recommends Apache or Nginx as the web server, so both are a sound base. Which one you pick doesn't decide whether your application works. It changes how you write the settings.

How does the stack work?

LayerLAMPLEMPRole
Operating systemLinuxLinuxThe base everything runs on
Web serverApacheNginxAnswers requests from browsers
DatabaseMySQL or MariaDBMySQL or MariaDBStores posts, users and orders
LanguagePHPPHP, through PHP-FPMBuilds the page

A request travels through the stack like this:

  1. The browser sends a request to your domain. It reaches port 80 or 443 on your server.
  2. The web server receives the request. If the request is for an image or a CSS file, it serves the file itself.
  3. If the request is for a PHP file, the web server hands it to PHP and PHP runs the code.
  4. PHP queries the database when needed and builds the page. The web server sends the page back to the browser.

If a page doesn't open, check the layers in order: systemctl status nginx, systemctl status phpX.Y-fpm and systemctl status mariadb. X.Y stands for your PHP version (8.3 on Ubuntu 24.04), and on LAMP you use apache2 instead of nginx. Whichever one isn't running is where the problem starts.

What is the difference between LAMP and LEMP?

  • Apache reads .htaccess files and Nginx doesn't. On Nginx, rules go into the server configuration.
  • Nginx doesn't run PHP inside itself. It passes requests to a separate service called PHP-FPM. Apache can run PHP inside itself or through PHP-FPM.
  • The configuration folders differ. On Ubuntu, Apache uses /etc/apache2 and Nginx uses /etc/nginx.
  • Memory use is decided more by the number of PHP-FPM workers and the database settings than by the choice of web server.
  • Neither is clearly superior. Both are widely used, so the guide you follow and your habits decide.

MySQL or MariaDB?

MariaDB is an open-source database that split off from MySQL, and their commands and clients are largely compatible. WordPress's official requirements page accepts both, so check the current minimum versions there. On Ubuntu, the mariadb-server package installs with one command. According to the MariaDB documentation, the root account has used unix_socket authentication by default since version 10.4. On the server, just run sudo mariadb. No root password is needed.

Setting up LEMP on Ubuntu

These steps are for Ubuntu and Debian. First connect to the server with SSH. The examples use example.com as the domain name, so replace it with your own.

  1. Refresh the package list: sudo apt update
  2. Install the packages: sudo apt install nginx mariadb-server php-fpm php-mysql. The versions installed are the ones in the package repository.
  3. Harden the database: sudo mariadb-secure-installation. Answer yes to removing anonymous users, removing the test database and disallowing remote root login.
  4. Create the site folder: sudo mkdir -p /var/www/example
  5. Open a file with sudo nano /etc/nginx/sites-available/example and paste this line: server { listen 80; server_name example.com www.example.com; root /var/www/example; index index.php index.html; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/phpX.Y-fpm.sock; } }
  6. ls /run/php/ shows the real name of the socket. Write that in place of phpX.Y-fpm.sock.
  7. Enable the site: sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/
  8. Test and apply the configuration: sudo nginx -t and then sudo systemctl reload nginx
  9. If you use ufw, open ports 80 and 443: sudo ufw allow 80/tcp and sudo ufw allow 443/tcp. Make sure the SSH port (22) is open.

To test that PHP works, write a test file:

echo '<?php phpinfo();' | sudo tee /var/www/example/info.php

If the domain doesn't point to the server yet, test from inside the server with curl -H 'Host: example.com' http://127.0.0.1/info.php. As soon as you see it work, delete the file: sudo rm /var/www/example/info.php. That page shows your server's details to everyone.

A database for your application

Open the database shell with sudo mariadb and create a separate database and user for each application. Choose a strong password yourself:

CREATE DATABASE exampledb CHARACTER SET utf8mb4;

CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'a-strong-password';

GRANT ALL ON exampledb.* TO 'exampleuser'@'localhost';

You enter these three values (database, user, password) on the WordPress setup screen. For WordPress permalinks to work, replace =404 in the Nginx line with /index.php?$args.

What changes for LAMP?

For the Apache stack, you install the packages like this:

sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql

You define the site under /etc/apache2/sites-available and turn it on with sudo a2ensite example. For permalinks, run sudo a2enmod rewrite and restart Apache with sudo systemctl restart apache2. For .htaccess files to take effect, you need to set AllowOverride All for the site's folder. You can also run Apache with PHP-FPM, which fits the event-driven event model. The database steps are the same as for LEMP.

After the installation

  • Add an HTTPS certificate. Let's Encrypt is free, and Certbot works with both Nginx and Apache.
  • Set the owner of the folders the web server needs to write to. On Ubuntu and Debian the web server runs as the www-data user: sudo chown -R www-data:www-data /var/www/example.
  • Install updates regularly with sudo apt update && sudo apt upgrade. After installation, operating system and software updates are your responsibility.
  • Back up the database separately with mariadb-dump. The daily server backup is included in the price, but you should still keep an extra copy of important data yourself.

If you want the stack ready to use, order with Seturack's LAMP or LEMP option and it installs itself. If all you need is WordPress, the WordPress VPS option is enough: the setup takes about 4-5 minutes, and the address and password appear in the panel.

Ready-made on Seturack: LAMP, LEMP.

Comments0

No Comments Yet

Be the first to share your thoughts.

Join the Discussion

Please sign in or sign up to leave a comment.

Never Miss a Post

Get our latest tutorials, guides and product news in your inbox.

You're subscribed to our newsletter.