LAMP — Linux, Apache, MySQL, PHP — is still the most common way to host PHP websites and apps on a VPS: WordPress, Laravel, phpMyAdmin, Moodle, and thousands of self-hosted tools all run on it. In this guide you will install a complete, working LAMP stack on a fresh Ubuntu 24.04 server using the current supported releases: Apache 2.4 serving pages, MySQL 8.4 LTS storing data, and PHP 8.4 executing your code. By the end you will have a verified, browser-tested server ready for a real app.

Two version choices matter here. Ubuntu 24.04's default repositories still ship MySQL 8.0, which reached end of life in April 2026 and no longer receives security patches, so this guide installs MySQL 8.4 LTS from Oracle's official APT repository instead. Ubuntu's built-in PHP is 8.3, which is now in security-fixes-only mode, so the guide installs PHP 8.4 from the well-known Ondřej Surý PPA, the same repository most production Ubuntu servers use.

Prerequisites

  • A server or VPS running Ubuntu 24.04 LTS (a local VM works too).
  • A non-root user with sudo access. Log in as that user.
  • Port 80 (and 443 later for SSL) reachable, with no firewall blocking it yet.
  • About 20–25 minutes.

Step 1 — Update the system

Always start from a fresh package index so you install the newest patched versions.

sudo apt update && sudo apt upgrade -y

This refreshes the package lists and upgrades anything outdated. On a brand-new VPS this can take a couple of minutes — let it finish.

Step 2 — Install Apache

Apache (httpd) is the "A" in LAMP: it listens on port 80/443 and serves your files.

sudo apt install apache2 -y
sudo systemctl enable --now apache2

The first command installs Apache 2.4; the second enables it to start at boot and starts it immediately. Check it is running:

sudo systemctl status apache2 --no-pager

Look for active (running). If UFW is active, allow web traffic through it:

sudo ufw allow 'Apache Full'

The Apache Full profile opens ports 80 and 443 together. Open http://your-server-ip in a browser — you should see the Ubuntu Apache default page. If you see it, Apache works.

Step 3 — Install MySQL 8.4 LTS from Oracle's repository

MySQL is the "M": the relational database your apps will read and write. Ubuntu 24.04's own repositories only offer MySQL 8.0, which is end of life, so add Oracle's official MySQL APT repository first. Download the repository configuration package (0.8.40-1 is the current release; if Oracle publishes a newer one, use that filename instead):

wget https://dev.mysql.com/get/mysql-apt-config_0.8.40-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.40-1_all.deb

A configuration dialog opens. Select MySQL Server & Cluster, then choose the mysql-8.4-lts series and confirm with Ok. Then refresh the package index and confirm APT now sees the 8.4 candidate:

sudo apt update
apt-cache policy mysql-server

The Candidate line should show an 8.4.x version from repo.mysql.com. If it still shows 8.0, re-run sudo dpkg-reconfigure mysql-apt-config and select the 8.4 LTS track. Now install and start MySQL:

sudo apt install mysql-server -y
sudo systemctl enable --now mysql

During installation you will be asked to set a root password and pick the default authentication plugin — keep the recommended caching_sha2_password; PHP's mysqlnd driver supports it, so your apps connect without extra work. Afterwards, run the security script to remove the remaining unsafe defaults:

sudo mysql_secure_installation

Answer y to the VALIDATE PASSWORD component, then accept the defaults to remove anonymous users, disallow remote root login, and drop the test database. Verify what you got:

mysql -V

You should see a MySQL 8.4.x version string. MySQL 8.4 is a Long Term Support release with support running to 2032, so this stack will not go stale next year. Note the difference from Ubuntu's bundled build: with Oracle's packages, root logs in with the password you set during installation (mysql -u root -p), not via socket auth.

Step 4 — Install PHP 8.4 and extensions

PHP is the "P": it executes your application code. Ubuntu 24.04's default PHP is 8.3, so add the Ondřej Surý PPA, which packages current PHP releases for Ubuntu, and install PHP 8.4 from it:

sudo apt install -y software-properties-common ca-certificates lsb-release apt-transport-https
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install -y php8.4 libapache2-mod-php8.4 php8.4-mysql php8.4-cli php8.4-curl php8.4-mbstring php8.4-xml php8.4-zip php8.4-gd

What each piece does: php8.4 is the interpreter itself; libapache2-mod-php8.4 plugs PHP into Apache so .php files execute instead of downloading; php8.4-mysql lets PHP talk to MySQL (WordPress and Laravel need it); the rest are common extensions apps expect. Confirm the version:

php -v

You should see PHP 8.4.x. PHP 8.4 is in active support until the end of 2026 with security fixes until 2028, and every major PHP app (WordPress, Laravel, Magento) fully supports it. PHP 8.5 is the newest stable branch if you want it — the same PPA carries it, just replace 8.4 with 8.5 in the package names — but check your app and plugins first, because 8.4 is still the safest production default. Restart Apache so the PHP module loads:

sudo systemctl restart apache2

Step 5 — Test that PHP executes

Create a small info page in Apache's default document root and fetch it:

echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php
curl http://localhost/info.php | head -20

If you see HTML output with PHP configuration details and a PHP 8.4 version banner, the full chain (Apache → mod_php → PHP) works. Delete the file immediately — phpinfo() exposes server details attackers love:

sudo rm /var/www/html/info.php

Step 6 — Create a database and app user

Never run your app as MySQL root. Create a dedicated database and user:

mysql -u root -p
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'myappuser'@'localhost' IDENTIFIED BY 'a-strong-password-here';
GRANT ALL PRIVILEGES ON myapp.* TO 'myappuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

This creates an empty myapp database, a user that can only connect from localhost, and grants it full rights on that database only — the standard, safe setup every PHP app installer expects. Test the login:

mysql -u myappuser -p -e "SHOW DATABASES;"

Type the password when prompted; you should see myapp in the list.

Step 7 — Point Apache at your app (virtual host)

If you are hosting a real site (not just the default page), create a virtual host. Replace example.com with your domain:

sudo mkdir -p /var/www/example.com/public_html
sudo chown -R $USER:$USER /var/www/example.com/public_html
sudo tee /etc/apache2/sites-available/example.com.conf > /dev/null <<'EOF'
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com/public_html
    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
EOF
sudo a2ensite example.com
sudo apache2ctl configtest
sudo systemctl reload apache2

AllowOverride All enables .htaccess files (WordPress permalinks need this). configtest should print Syntax OK before you reload. Point your domain's DNS A-record at the server IP and your site is live.

Verify it worked

Run this quick health check on the whole stack:

sudo systemctl is-active apache2 mysql
php -v | head -1
mysql -u myappuser -p -e "SELECT VERSION();"
curl -s -o /dev/null -w "%{http_code}\n" http://localhost/

You want: active / active, PHP 8.4.x, a MySQL 8.4.x version string, and HTTP 200. Open http://your-server-ip in a browser as a final visual check.

Common issues & fixes

1. Browser can't reach the Apache default page

Almost always the firewall. Check UFW status and the Apache profile:

sudo ufw status
sudo ufw allow 'Apache Full'

If you are on a cloud provider (AWS, Hetzner, DigitalOcean), also open port 80 in the provider's security group / cloud firewall — UFW alone is not enough there.

2. PHP file downloads instead of executing

The PHP module isn't loaded in Apache. Re-enable it and restart:

sudo a2enmod php8.4
sudo systemctl restart apache2

3. APT installs MySQL 8.0 instead of 8.4

The repository track was not switched. Reconfigure the package, select the mysql-8.4-lts series, update, and check the candidate again before installing:

sudo dpkg-reconfigure mysql-apt-config
sudo apt update
apt-cache policy mysql-server

4. "Address already in use" when starting Apache

Something else (usually Nginx) is already on port 80. Find it and choose one web server:

sudo ss -tlnp | grep ':80'

Stop/disable the other service (sudo systemctl stop nginx) or move one of them to a different port.

5. App installer complains about a missing PHP extension

Install the named extension for PHP 8.4 and reload Apache — the pattern is always the same:

sudo apt install -y php8.4-intl
sudo systemctl reload apache2

Conclusion

You now have a complete, current LAMP stack on Ubuntu 24.04: Apache 2.4 serving requests, MySQL 8.4 LTS holding your data, PHP 8.4 running your code, a dedicated app database user, and a virtual host ready for a domain. Next steps for a production site: add free HTTPS with Let's Encrypt, lock down SSH, and set up automated MySQL backups.

Setting up servers is what we do every day — if you'd rather have it done right the first time, XpertBees offers managed server setup and hardening for Ubuntu VPS deployments.