Key takeaways
- LAMP runs most PHP applications, including WordPress.
- Secure MySQL right after installing it.
- Remove test files like info.php when finished.
These steps assume Ubuntu 24.04 and a user with sudo rights.
1. Apache
sudo apt update
sudo apt install apache2
sudo ufw allow 'Apache Full'
Visit http://your-server-ip — you should see the Apache default page.
2. MySQL
sudo apt install mysql-server
sudo mysql_secure_installation
Answer yes to removing anonymous users, disallowing remote root login and removing the test database.
Create a database and user for your application:
sudo mysql
CREATE DATABASE app;
CREATE USER 'app'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON app.* TO 'app'@'localhost';
FLUSH PRIVILEGES;
EXIT;
3. PHP
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip
sudo systemctl restart apache2
4. Test PHP
echo '<?php phpinfo();' | sudo tee /var/www/html/info.php
Open http://your-server-ip/info.php, confirm it shows the PHP version, then delete it: sudo rm /var/www/html/info.php.
Next steps
Create a virtual host for your domain, point DNS at the server, and add a free certificate with Certbot.
Frequently asked questions
Should I choose LAMP or LEMP?
Both work well. Apache supports .htaccess files, which many PHP apps rely on. Nginx (LEMP) uses less memory under heavy load. Pick what your application documents.
MySQL or MariaDB?
Either is fine for most sites. MariaDB is a drop-in replacement for MySQL and is the default on many distributions.