Menu
User

DropVPS Team

Writer: Cooper Reagan

how to install lemp stack on ubuntu 25.04

how to install lemp stack on ubuntu 25.04

Publication Date

09/21/2025

Category

Articles

Reading Time

3 Min

Table of Contents

The LEMP stack (Linux, Nginx, MySQL/MariaDB, and PHP) is a popular open-source web server environment used to host modern websites and web applications. Unlike the traditional LAMP stack, it uses Nginx instead of Apache, which offers better performance under heavy loads.

Step 1: Update Your System

Always start by updating your server to ensure you have the latest packages and security patches:

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx

Nginx is the web server that will handle incoming requests.

sudo apt install nginx -y
Enable and start Nginx:
sudo systemctl enable nginx
sudo systemctl start nginx

Test it by opening your browser and navigating to:

http://your_server_ip

Step 3: Install MySQL (or MariaDB)

The database will store your application data. Install MySQL with:

sudo apt install mysql-server -y

Secure your installation:

sudo mysql_secure_installation

Log into MySQL to confirm:

sudo mysql -u root -p

Step 4: Install PHP and Extensions

PHP connects Nginx with MySQL to run dynamic web applications:

sudo apt install php-fpm php-mysql -y

Step 5: Configure Nginx to Use PHP

Open a new Nginx server block file:

sudo nano /etc/nginx/sites-available/myapp

Add this configuration:

server {
    listen 80;
    server_name myapp.local;

    root /var/www/html/myapp;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Enable the configuration and restart Nginx:

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 6: Test PHP Processing

Create a test file:

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

Open in your browser:

http://your_server_ip/index.php

If you see the PHP info page, everything works!

The LEMP stack is now installed and configured on Ubuntu 25.04. Your system is ready to serve dynamic PHP applications backed by MySQL and powered by the high-performance Nginx web server.

Linux VPS
U
Loading...

Related Posts