How to Install LAMP Stack on Ubuntu 24.04
Learn how to install lamp stack on ubuntu 24.04 with Apache 2.4, MySQL 8.0, PHP 8.3, UFW firewall rules, and Apache virtual host configurations.

5 min read
Learn how to install lamp stack on ubuntu 24.04 with Apache 2.4, MySQL 8.0, PHP 8.3, UFW firewall rules, and Apache virtual host configurations.
- Prerequisites and Supported Releases
- Step 1: Installing and Configuring Apache HTTP Server
- Step 2: Installing and Securing MySQL 8.0 Database Server
The LAMP stack—consisting of Linux (operating system), Apache HTTP Server (web server), MySQL (relational database management system), and PHP (server-side programming language)—is the time-tested, foundational software bundle that shaped the modern dynamic World Wide Web.
Renowned for its unparalleled simplicity, comprehensive documentation, and broad native compatibility with platforms like WordPress, Drupal, Joomla, and Magento, LAMP remains the default development environment for millions of web developers globally.
Ubuntu 24.04 LTS (Noble Numbat) packages the latest stable releases of each component natively, including Apache 2.4, MySQL 8.0, and PHP 8.3.
In this guide, we walk through how to install lamp stack on ubuntu from package installation to configuring Apache Virtual Hosts and verifying PHP processing.
Complete step-by-step developer and system administrator tutorial on installing and securing the classic LAMP (Linux, Apache, MySQL, PHP) web development stack on Ubuntu 24.04 LTS (Noble Numbat). Covers Apache 2.4 installation and module tuning, MySQL 8.0 database security, PHP 8.3 integration, Apache Virtual Host creation, and testing dynamic PHP execution.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A server or virtual machine running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- A non-root user account with
sudoadministrative privileges. - UFW firewall installed.
- Basic familiarity with terminal command-line operations.
Step 1: Installing and Configuring Apache HTTP Server
Apache is one of the world's most widely used web servers, known for its modular architecture, robust .htaccess directory-level configuration support, and broad language modules.
First, update your local APT repository index, then install the apache2 package:
Allow web traffic through UFW and verify that Apache is active:
# Update package lists and install Apache:
sudo apt update
sudo apt install -y apache2
# Allow HTTP (80) and HTTPS (443) through UFW:
sudo ufw allow 'Apache Full'
# Verify Apache service status:
sudo systemctl status apache2
# Expected output confirms: Active: active (running)
Step 2: Installing and Securing MySQL 8.0 Database Server
With Apache serving web content, install MySQL to store and manage relational database records for your applications.
Install the mysql-server package using apt:
Execute the interactive security script to configure root password security and eliminate sample test privileges:
# Install MySQL Server:
sudo apt install -y mysql-server
# Run interactive security configuration:
sudo mysql_secure_installation
# Recommendations during prompts:
# - Enable VALIDATE PASSWORD component? [Y] (optional)
# - Set strong root password
# - Remove anonymous users? [Y]
# - Disallow root login remotely? [Y]
# - Remove test database? [Y]
# - Reload privilege tables now? [Y]
Step 3: Installing PHP 8.3 and Apache PHP Integration
PHP processes dynamic server-side scripts and interacts with MySQL to render HTML content for client web browsers.
Ubuntu 24.04 includes PHP 8.3 in the main repository archives.
Install PHP along with the Apache PHP module (libapache2-mod-php), the MySQL database connector (php-mysql), and standard web libraries:
# Install PHP and essential Apache/MySQL modules:
sudo apt install -y php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip
# Verify installed PHP version:
php -v
# Expected output confirms: PHP 8.3.x (cli) ...
Step 4: Configuring an Apache Virtual Host
Apache Virtual Hosts allow a single server instance to host multiple distinct domains and websites, each with its own document root and logging policies.
Create a dedicated website directory at /var/www/example.com/html and assign ownership to your non-root user:
Create a new Virtual Host configuration file in /etc/apache2/sites-available/example.com.conf:
# Create document root directory:
sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com
# /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
<Directory /var/www/example.com/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>
Enabling the Virtual Host and mod_rewrite
Enable your new Virtual Host configuration using a2ensite, enable the essential rewrite module for clean SEO URLs, and reload Apache:
# Enable the Virtual Host configuration:
sudo a2ensite example.com.conf
# Enable the Apache URL rewrite module (required by WordPress and frameworks):
sudo a2enmod rewrite
# Test Apache syntax configuration:
sudo apache2ctl configtest
# Output confirms: Syntax OK
# Restart Apache web server:
sudo systemctl restart apache2
Step 5: Testing Dynamic PHP Processing in Apache
Confirm that Apache executes PHP scripts correctly rather than downloading them as raw text files.
Create a test file named info.php inside your document root:
Query the page via curl or visit the URL in your web browser:
# Create PHP verification file:
echo '<?php phpinfo(); ?>' > /var/www/example.com/html/info.php
# Test HTTP response using curl:
curl -I http://example.com/info.php
# Expected output confirms: HTTP/1.1 200 OK
# Remove test file for security:
rm -f /var/www/example.com/html/info.php
Step 6: Securing the LAMP Web Server with Let's Encrypt SSL
Production web servers must encrypt web traffic using HTTPS to safeguard user authentication sessions and sensitive transactional data.
Install Certbot alongside the Apache Certbot plugin to automate certificate acquisition and scheduled renewals:
Execute Certbot to generate trusted TLS certificates and automatically configure Apache SSL virtual hosts:
Certbot installs automated systemd timers to seamlessly renew certificates prior to their expiration.
# Install Certbot and Apache plugin:
sudo apt install -y certbot python3-certbot-apache
# Obtain and configure SSL certificate for your domain:
sudo certbot --apache -d example.com -d www.example.com
# Verify automated certificate renewal dry-run:
sudo certbot renew --dry-run
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name
Cause: Apache lacks a global ServerName directive in /etc/apache2/apache2.conf.
Resolution: Add ServerName 127.0.0.1 to the bottom of /etc/apache2/apache2.conf and restart Apache.
echo 'ServerName 127.0.0.1' | sudo tee -a /etc/apache2/apache2.conf && sudo systemctl restart apache2
Access denied for user 'root'@'localhost' in MySQL
Cause: MySQL uses auth_socket by default on Ubuntu, requiring sudo for root logins.
Resolution: Log in using sudo: sudo mysql -u root.
sudo mysql -u root
403 Forbidden error when visiting Apache Virtual Host
Cause: Incorrect filesystem permissions on /var/www/ or missing Require all granted in Virtual Host.
Resolution: Set directory permissions to 755: sudo chmod -R 755 /var/www/example.com.
sudo chmod -R 755 /var/www/example.com
Security Best Practices and Hardening
Ensure AllowOverride All is restricted strictly to your website's document root directory in Apache configuration.
Disable server signature banners by setting ServerSignature Off and ServerTokens Prod in /etc/apache2/conf-available/security.conf.
Secure website traffic with automated free SSL/TLS certificates via Certbot: sudo apt install -y certbot python3-certbot-apache && sudo certbot --apache -d example.com.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install and Secure MySQL on Ubuntu 24.04 — Deep dive into MySQL database administration and user privilege setup.
- How to Install LEMP Stack on Ubuntu 24.04 — Compare classic Apache LAMP stacks with event-driven Nginx LEMP architectures.
- Initial Server Setup on Ubuntu 24.04 LTS — Establish foundational server security and package repository baselines.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/etc/apache2/sites-available/ and pointing each to a distinct document root in /var/www/, a single LAMP server can host dozens of different websites simultaneously.sudo systemctl restart apache2 and restart MySQL with sudo systemctl restart mysql.mod_php embeds the PHP interpreter directly into every Apache worker process, which is simple to set up but memory-intensive. php-fpm processes PHP scripts in an isolated daemon, allowing Apache to run with high-performance event MPM mode./var/log/apache2/access.log and error logs in /var/log/apache2/error.log.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!