The LAMP stack — Linux, Apache, MySQL, PHP — still powers a huge share of the web, including WordPress, Joomla, Magento and most PHP applications. On Ubuntu 24.04 you get Apache 2.4, MySQL 8.0 and PHP 8.3 straight from the official repositories, and the whole installation takes about ten minutes. Complete your initial server setup first, then follow along.
Step 1 — Install the whole stack
sudo apt update sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql -y
Open your server's IP in a browser — you should see the default “Apache2 Ubuntu Default Page”. If not, allow web traffic through the firewall:
sudo ufw allow "Apache Full"
Step 2 — Secure MySQL
sudo mysql_secure_installation
Answer y to removing anonymous users, disallowing remote root login and dropping the test database.
Then create a dedicated database and user for your application — applications should never connect as root:
sudo mysql CREATE DATABASE myapp; CREATE USER 'myapp'@'localhost' IDENTIFIED BY 'Str0ng-Pass-Here!'; GRANT ALL PRIVILEGES ON myapp.* TO 'myapp'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 3 — Test PHP
echo '<?php phpinfo();' | sudo tee /var/www/html/info.php
Visit http://your_server_ip/info.php — the PHP information page confirms Apache is executing PHP. Delete the file afterwards; it leaks configuration details attackers love:
sudo rm /var/www/html/info.php
Step 4 — Set up a virtual host for your domain
sudo mkdir -p /var/www/example.com sudo nano /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
sudo a2ensite example.com.conf sudo a2dissite 000-default.conf sudo apache2ctl configtest && sudo systemctl reload apache2
Step 5 — Useful PHP extensions
Most PHP applications (WordPress included) want these:
sudo apt install php-curl php-gd php-mbstring php-xml php-zip php-intl -y
Next steps
Point your domain's DNS at the server, then secure the site with a free Lets Encrypt SSL certificate — Certbot's Apache plugin automates the whole thing. Keep the stack patched with automatic security updates, and if you expect high traffic, consider the LEMP variant with Nginx, which handles heavy concurrency with less memory.
Related Ubuntu guides
- How to Install a LEMP Stack (Nginx, MySQL, PHP) on Ubuntu 24.04
- How to Get a Free SSL Certificate on Ubuntu with Lets Encrypt and Certbot
- Initial Ubuntu 24.04 Server Setup Guide: Secure Your New VPS in 10 Steps
- How to Update Ubuntu Server: apt, Security Patches and Unattended Upgrades
Prefer to have experts handle it?
LFA IT provides fully managed Ubuntu VPS and dedicated servers — initial setup, security hardening, monitoring and 24/7 support, so you can focus on your business. Explore our hosting and server management services or open a support ticket and our engineers will take it from there.