✅ Ubuntu 24.04 Full Setup: LAMP Stack + Docker & Docker Compose (One Script)
If you’re setting up a new Ubuntu 24.04 server (Noble Numbat) and want a complete environment for web development, this guide is for you.
This tutorial installs:
✅ Apache2
✅ MySQL Server
✅ PHP (7.4 / 8.0 / 8.1 / 8.2 / 8.3 / 8.4)
✅ Common PHP extensions
✅ phpMyAdmin (optional)
✅ Docker + Docker Compose (official repo)
✅ UFW firewall rules (optional)
⚠️ Notes Before You Start
✅ PHP versions
Ubuntu 24.04 default PHP is usually 8.3, but this guide supports multiple PHP versions using the widely used Ondrej PHP PPA.
✅ Supported versions:
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
⚠️ PHP 8.5 does not exist yet (latest is…
✅ Ubuntu 24.04 Full Setup: LAMP Stack + Docker & Docker Compose (One Script)
If you’re setting up a new Ubuntu 24.04 server (Noble Numbat) and want a complete environment for web development, this guide is for you.
This tutorial installs:
✅ Apache2
✅ MySQL Server
✅ PHP (7.4 / 8.0 / 8.1 / 8.2 / 8.3 / 8.4)
✅ Common PHP extensions
✅ phpMyAdmin (optional)
✅ Docker + Docker Compose (official repo)
✅ UFW firewall rules (optional)
⚠️ Notes Before You Start
✅ PHP versions
Ubuntu 24.04 default PHP is usually 8.3, but this guide supports multiple PHP versions using the widely used Ondrej PHP PPA.
✅ Supported versions:
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
⚠️ PHP 8.5 does not exist yet (latest is PHP 8.4).
✅ Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
✅ Step 2: Create the Full Installation Script
Create a script file:
nano full_setup_ubuntu24.sh
Now paste this script 👇
✅ Full Script: Apache + MySQL + PHP + Docker (Ubuntu 24.04)
🔥 Before running, change these values inside the script:
PHP_VERSIONMYSQL_ROOT_PASSWORD
#!/bin/bash
set -e
# -----------------------------
# CONFIG (EDIT THESE)
# -----------------------------
PHP_VERSION="8.4" # Options: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4
MYSQL_ROOT_PASSWORD="Root@12345" # Change this
INSTALL_PHPMYADMIN="yes" # yes/no
ENABLE_UFW="yes" # yes/no
# -----------------------------
echo "==========================================="
echo " Ubuntu 24.04 Full Setup: LAMP + Docker"
echo " Apache2 + MySQL + PHP $PHP_VERSION + Docker"
echo "==========================================="
# Check root
if [ "$EUID" -ne 0 ]; then
echo "❌ Please run as root: sudo bash full_setup_ubuntu24.sh"
exit 1
fi
echo "✅ Updating system..."
apt update && apt upgrade -y
echo "✅ Installing basic tools..."
apt install -y software-properties-common curl ca-certificates gnupg lsb-release unzip
# -----------------------------
# Apache2 Install
# -----------------------------
echo "✅ Installing Apache2..."
apt install -y apache2
systemctl enable --now apache2
# -----------------------------
# MySQL Install
# -----------------------------
echo "✅ Installing MySQL Server..."
apt install -y mysql-server
systemctl enable --now mysql
echo "✅ Setting MySQL root password + mysql_native_password..."
mysql -u root <<MYSQL_SCRIPT
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${MYSQL_ROOT_PASSWORD}';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
# -----------------------------
# PHP Install (Ondrej PPA)
# -----------------------------
echo "✅ Adding PHP PPA (ondrej/php)..."
add-apt-repository ppa:ondrej/php -y
apt update -y
echo "✅ Installing PHP ${PHP_VERSION}..."
apt install -y \
php${PHP_VERSION} \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-mysql \
libapache2-mod-php${PHP_VERSION}
echo "✅ Installing common PHP extensions..."
apt install -y \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-zip \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-intl \
php${PHP_VERSION}-bcmath
echo "✅ Restarting Apache..."
systemctl restart apache2
# -----------------------------
# PHP Info test file
# -----------------------------
echo "✅ Creating PHP test file: /var/www/html/info.php"
cat > /var/www/html/info.php <<EOF
<?php
phpinfo();
?>
EOF
# -----------------------------
# Optional: phpMyAdmin
# -----------------------------
if [ "${INSTALL_PHPMYADMIN}" = "yes" ]; then
echo "✅ Installing phpMyAdmin..."
apt install -y phpmyadmin || true
phpenmod mbstring || true
systemctl restart apache2
fi
# -----------------------------
# Docker Install (Official Repo)
# -----------------------------
echo "✅ Installing Docker + Docker Compose (official)..."
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
> /etc/apt/sources.list.d/docker.list
apt update -y
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker
# Add current user to docker group
if [ -n "$SUDO_USER" ]; then
echo "✅ Adding user '$SUDO_USER' to docker group..."
usermod -aG docker $SUDO_USER
fi
# -----------------------------
# UFW Firewall (Optional)
# -----------------------------
if [ "${ENABLE_UFW}" = "yes" ]; then
echo "✅ Setting up UFW firewall..."
apt install -y ufw
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
ufw status verbose
fi
# -----------------------------
# Finished Summary
# -----------------------------
echo "==========================================="
echo "✅ INSTALLATION COMPLETE!"
echo "==========================================="
echo "Apache: systemctl status apache2"
echo "MySQL: systemctl status mysql"
echo "PHP: php -v"
echo "Docker: docker --version"
echo "Compose: docker compose version"
echo ""
echo "🔑 MySQL root password set to:"
echo " ${MYSQL_ROOT_PASSWORD}"
echo ""
echo "✅ PHP test page created:"
echo " http://YOUR_SERVER_IP/info.php"
echo ""
echo "⚠️ IMPORTANT: Delete info.php after testing:"
echo " sudo rm /var/www/html/info.php"
echo ""
echo "✅ If Docker group added, logout/login required for it to work without sudo."
echo "==========================================="
✅ Step 3: Make the Script Executable
chmod +x full_setup_ubuntu24.sh
✅ Step 4: Run the Script
sudo bash full_setup_ubuntu24.sh
✅ Step 5: Verify Installations
✅ Apache2
systemctl status apache2
Test in browser:
http://YOUR_SERVER_IP
✅ MySQL
systemctl status mysql
Login:
mysql -u root -p
✅ PHP
php -v
✅ Docker
docker --version
docker compose version
Test Docker:
docker run hello-world
✅ Step 6: Check PHP Working in Browser
This script creates a PHP test page:
http://YOUR_SERVER_IP/info.php
✅ After confirming PHP is working, remove it for security:
sudo rm /var/www/html/info.php
✅ Optional: phpMyAdmin
If you enabled phpMyAdmin in the script, open:
http://YOUR_SERVER_IP/phpmyadmin