Before You Start
- A user with sudo rights: see create a sudo user on Ubuntu.
- An updated system:
sudo apt update && sudo apt upgrade. - A domain pointing at the server, if you want HTTPS at the end.
Step 1: Install Apache and Open the Firewall
Allow SSH, or your custom SSH port, before you enable ufw, or the firewall cuts off your session:
sudo apt install apache2
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enableOpen http://203.0.113.10 with your server's IP address; the Apache default page should load. More in how to install Apache.
Step 2: Install MySQL
sudo apt install mysql-server
sudo mysql_secure_installationThe script offers password strength checks, removes anonymous users and the test database, and disallows remote root login; answer yes to those. On Ubuntu the MySQL root account uses socket authentication, so sudo mysql opens the SQL shell for local administration without a database password. The details are in how to install MySQL on Ubuntu.
On Debian, install mariadb-server instead and run sudo mariadb-secure-installation.
Step 3: Install PHP
sudo apt install php libapache2-mod-php php-mysql
php -vlibapache2-mod-php is the Apache module that runs PHP inside Apache's own processes: the classic LAMP setup. Installing it switches Apache from the event MPM to prefork. php-mysql adds the extension PHP uses to talk to MySQL. Ubuntu 24.04 ships PHP 8.3 and Ubuntu 26.04 ships PHP 8.5. Paths below use 8.3; replace 8.3 with your version. Versions and extensions are covered in how to install PHP on Ubuntu.
Step 4: Test PHP, Then Delete the Test
echo '<?php phpinfo();' | sudo tee /var/www/html/info.phpOpen http://203.0.113.10/info.php in a browser. The page shows the PHP version and, under Server API, Apache 2.0 Handler (Apache 2 Handler from PHP 8.4 on); with PHP-FPM it reads FPM/FastCGI. Delete the file right away, because it shows paths and settings to anyone who finds it:
sudo rm /var/www/html/info.phpStep 5: Create a Database for Your Site
sudo mysqlIn the SQL shell:
CREATE DATABASE app;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON app.* TO 'app_user'@'localhost';
EXIT;Type the real password here, not on a shell command line, where it would stay in your history and show in the process list. One user per application, limited to its own database, limits the damage if that application is compromised.
Optional: PHP-FPM Instead of mod_php
mod_
sudo apt install php-fpm
sudo a2dismod php8.3 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo apachectl configtest
sudo systemctl restart apache2Use a full restart here rather than a reload: the MPM changes, and a2enmod asks for a restart. Tuning is covered in what is PHP-FPM.
Step 6: Add a Site and HTTPS
Give your site its own folder and configuration, as in how to set up Apache virtual hosts, then get a certificate with Certbot Apache. To run WordPress on this stack, continue with how to install WordPress with Apache.
Check the Whole Stack
systemctl status apache2 mysql
sudo ss -tlnp | grep -E ':80 |:3306 'Both services should be active. MySQL should listen on 127.0.0.1 only, which is Ubuntu's default; do not open port 3306 in the firewall unless another server needs the database.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations