Docker Compose simplifies deploying multi-service applications. This guide walks through creating a production-ready Docker Compose deployment for a LEMP stack (Nginx, MySQL, PHP) on Ubuntu 24.04 LTS.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • Docker Engine and Docker Compose plugin installed
  • A user in the docker group

Step 1 – Create the Project Directory

Set up the project structure:

mkdir -p ~/lemp-app/{nginx,php,mysql,app}
cd ~/lemp-app

Step 2 – Create the Nginx Configuration

Create nginx/default.conf:

server {
    listen 80;
    root /var/www/html;
    index index.php index.html;
    location ~ .php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Step 3 – Create a Test PHP File

Create app/index.php:

<?php
phpinfo();

Step 4 – Create docker-compose.yml

Define all services:

version: '3.9'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./app:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php

  php:
    image: php:8.3-fpm
    volumes:
      - ./app:/var/www/html

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: appdb
      MYSQL_USER: appuser
      MYSQL_PASSWORD: apppass
    volumes:
      - mysql_data:/var/lib/mysql

volumes:
  mysql_data:

Step 5 – Start the Stack

Start all services:

docker compose up -d

Verify all containers are running:

docker compose ps

Step 6 – Update and Redeploy

After making changes, rebuild and restart:

docker compose build
docker compose up -d

Step 7 – View Logs

Follow logs from all or a specific service:

docker compose logs -f
docker compose logs -f nginx

Conclusion

A LEMP stack is now deployed with Docker Compose on Ubuntu 24.04 LTS. Docker Compose makes it easy to reproduce the same environment across development, staging, and production.