LAMP — Linux, Apache, MySQL, PHP — is one of the most established web server stacks, and setting it up on a fresh Ubuntu server is a matter of installing four pieces separately and confirming they're correctly wired together.
Step 1: Update the system
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
Visiting the server's IP address in a browser at this point should show Apache's default "It works!" placeholder page — a useful checkpoint confirming the web server itself is running correctly before adding the database and PHP layers.
Step 3: Install MySQL
sudo apt install mysql-server -y
sudo mysql_secure_installation
mysql_secure_installation is an interactive script that removes several insecure defaults left over from a fresh install — anonymous users, a test database accessible without authentication, and remote root login — all of which are genuinely worth removing on any server exposed to the internet.
Step 4: Install PHP and required extensions
sudo apt install php libapache2-mod-php php-mysql -y
libapache2-mod-php is the specific package that lets Apache actually execute PHP files, rather than just serving them as plain text — installing PHP itself without this module means .php files would download as raw source code instead of running.
Step 5: Restart Apache to load the PHP module
sudo systemctl restart apache2
Step 6: Verify PHP is working correctly
echo "" | sudo tee /var/www/html/info.php
Visiting http://your-server-ip/info.php should display the full PHP configuration page — this confirms Apache is genuinely executing PHP, not just serving the file's raw text; the file should be deleted afterward, since phpinfo() exposes detailed server configuration that shouldn't be publicly accessible on a real server.
sudo rm /var/www/html/info.php
Configuring a virtual host for a real project
Following the Apache virtual host pattern covered elsewhere on this site, a real project needs its own virtual host file pointing DocumentRoot at the project's public directory (for a Laravel app) rather than serving directly from Apache's default /var/www/html.
Checking the status of all three services
sudo systemctl status apache2
sudo systemctl status mysql
php -v
Common issue: firewall blocking the web server
sudo ufw allow 'Apache Full'
sudo ufw status
If Apache is confirmed running but the site is still unreachable from a browser, checking whether ufw (Ubuntu's firewall) is actively blocking port 80/443 is a common and easy-to-overlook next troubleshooting step.