
How to Install WordPress on Ubuntu 24 with a LAMP Stack
Installing WordPress on Ubuntu 24 with a LAMP stack is one of the most reliable and performance-efficient ways to get your WordPress site up and running. The LAMP stack (Linux, Apache, MySQL, PHP) provides a robust foundation that powers millions of websites worldwide, offering excellent stability, security, and customization options. In this guide, you’ll learn how to set up a complete LAMP environment on Ubuntu 24, configure each component properly, install WordPress, and optimize the setup for production use while avoiding common pitfalls that can compromise performance or security.
Understanding the LAMP Stack Architecture
The LAMP stack consists of four core components that work together to serve dynamic web content. Linux (Ubuntu 24) acts as the operating system foundation, Apache handles HTTP requests and serves web pages, MySQL manages database operations for storing WordPress content, and PHP processes server-side scripts that generate dynamic pages.
When a user visits your WordPress site, Apache receives the HTTP request and passes it to PHP, which executes WordPress code and queries the MySQL database for content. The PHP engine then generates HTML output that Apache sends back to the user’s browser. This architecture separates concerns effectively and allows for horizontal scaling as your site grows.
Prerequisites and System Preparation
Before starting the installation, ensure your Ubuntu 24 server meets the minimum requirements and has proper network connectivity. You’ll need root or sudo access, at least 1GB of RAM (2GB recommended), and 10GB of available disk space.
First, update your system packages to ensure you’re working with the latest versions:
sudo apt update && sudo apt upgrade -y
sudo apt install curl wget unzip -y
Check your Ubuntu version to confirm you’re running 24.x:
lsb_release -a
Installing and Configuring Apache Web Server
Apache 2.4 comes with Ubuntu 24’s repositories and includes modern features like HTTP/2 support and improved security modules. Install Apache and enable it to start automatically:
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
Configure the firewall to allow HTTP and HTTPS traffic:
sudo ufw allow 'Apache Full'
sudo ufw enable
Test your Apache installation by visiting your server’s IP address in a browser. You should see the Apache2 Ubuntu default page. To find your server’s IP address:
ip addr show | grep inet
Enable essential Apache modules for WordPress:
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo systemctl restart apache2
Setting Up MySQL Database Server
MySQL 8.0 is the default version in Ubuntu 24 repositories and offers significant performance improvements over previous versions, including better JSON support and enhanced security features.
sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql
Secure your MySQL installation by running the security script:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disable remote root login, and remove test databases. For production environments, always choose ‘Y’ for all security questions.
Create a dedicated database and user for WordPress:
sudo mysql -u root -p
Execute these SQL commands in the MySQL prompt:
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_strong_password_here';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Installing and Configuring PHP
Ubuntu 24 includes PHP 8.3 by default, which offers excellent performance improvements and new features compared to older versions. Install PHP along with essential extensions for WordPress:
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-xml php-mbstring php-xmlrpc php-zip php-soap php-intl -y
Configure PHP settings for optimal WordPress performance by editing the main PHP configuration file:
sudo nano /etc/php/8.3/apache2/php.ini
Modify these key settings for better WordPress performance:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_vars = 3000
Test PHP functionality by creating a test file:
sudo nano /var/www/html/info.php
Add this content:
<?php
phpinfo();
?>
Visit http://your_server_ip/info.php to verify PHP is working correctly. Remove this file after testing for security reasons:
sudo rm /var/www/html/info.php
Downloading and Installing WordPress
Download the latest WordPress release directly from the official repository:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xvf latest.tar.gz
Create the WordPress directory and move files:
sudo mkdir -p /var/www/html/wordpress
sudo cp -R /tmp/wordpress/* /var/www/html/wordpress/
Set proper ownership and permissions for WordPress files:
sudo chown -R www-data:www-data /var/www/html/wordpress/
sudo chmod -R 755 /var/www/html/wordpress/
Create the WordPress configuration file from the sample:
cd /var/www/html/wordpress/
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update the database configuration section with your MySQL details:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wordpress_user');
define('DB_PASSWORD', 'your_strong_password_here');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', 'utf8mb4_unicode_ci');
Generate unique security keys by visiting https://api.wordpress.org/secret-key/1.1/salt/ and replace the placeholder keys in wp-config.php with the generated values.
Configuring Apache Virtual Hosts
Create a dedicated virtual host configuration for your WordPress site:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add this configuration:
<VirtualHost *:80>
ServerName your_domain.com
ServerAlias www.your_domain.com
DocumentRoot /var/www/html/wordpress
<Directory /var/www/html/wordpress/>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/wordpress_error.log
CustomLog /var/log/apache2/wordpress_access.log combined
</VirtualHost>
Enable the new site and disable the default Apache site:
sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
Performance Comparison: LAMP vs Alternative Stacks
Stack | Average Response Time | Memory Usage | Setup Complexity | Community Support |
---|---|---|---|---|
LAMP (Apache/MySQL/PHP) | 120ms | 45MB | Medium | Excellent |
LEMP (Nginx/MySQL/PHP) | 95ms | 35MB | Medium-High | Very Good |
LAMP with MariaDB | 115ms | 42MB | Medium | Good |
WordPress.com Hosting | 200ms | N/A | Low | Limited |
Completing WordPress Installation
Navigate to your domain or server IP address in a web browser to complete the WordPress installation wizard. You’ll be prompted to select a language, then provide site information:
- Site title and description
- Administrator username (avoid ‘admin’ for security)
- Strong administrator password
- Administrator email address
- Search engine visibility preferences
After completing the wizard, log in to your WordPress dashboard and verify all functionality is working correctly.
Security Hardening and Best Practices
Implement these security measures to protect your WordPress installation:
Hide sensitive files by adding this to your virtual host configuration:
<Files "wp-config.php">
Require all denied
</Files>
<Files ".htaccess">
Require all denied
</Files>
Create a comprehensive .htaccess file in your WordPress root directory:
sudo nano /var/www/html/wordpress/.htaccess
Add security and performance optimizations:
# BEGIN WordPress Security
<Files wp-config.php>
order allow,deny
deny from all
</Files>
# Disable directory browsing
Options -Indexes
# Protect against script injections
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(HEAD|TRACE|DELETE|TRACK) [NC]
RewriteRule ^(.*)$ - [F,L]
# Enable compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Common Issues and Troubleshooting
Here are the most frequent problems encountered during LAMP WordPress installations and their solutions:
Issue: “Error establishing a database connection”
This typically indicates incorrect database credentials or MySQL service problems. Verify your wp-config.php database settings and test MySQL connectivity:
mysql -u wordpress_user -p wordpress_db
Issue: Apache not serving PHP files
Ensure mod_php is enabled and PHP files are being processed:
sudo a2enmod php8.3
sudo systemctl restart apache2
Issue: File permissions errors
Reset WordPress file permissions to the recommended values:
sudo find /var/www/html/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/wordpress/ -type f -exec chmod 644 {} \;
sudo chmod 600 /var/www/html/wordpress/wp-config.php
Issue: Memory limit exhausted errors
Increase PHP memory limits in wp-config.php by adding this line before the “stop editing” comment:
ini_set('memory_limit', '256M');
Performance Optimization and Monitoring
Install and configure Apache’s mod_pagespeed for automatic optimization:
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
sudo dpkg -i mod-pagespeed-*.deb
sudo systemctl restart apache2
Enable MySQL slow query logging to identify performance bottlenecks:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Add these lines under the [mysqld] section:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
Monitor system resources using built-in tools:
htop
iotop
mysqladmin -u root -p status
Real-World Use Cases and Applications
This LAMP WordPress setup is particularly well-suited for several scenarios:
- Corporate websites – The stability and extensive plugin ecosystem make LAMP ideal for business sites requiring custom functionality
- E-commerce platforms – WooCommerce runs efficiently on LAMP stacks with proper optimization
- Multi-site networks – WordPress multisite installations benefit from MySQL’s robust transaction handling
- Development environments – Easy to replicate and version control for team development workflows
- High-traffic blogs – With proper caching, can handle 10,000+ concurrent users
For production deployments, consider implementing additional components like Redis for object caching, Elasticsearch for search functionality, and CDN integration for global content delivery.
Backup and Maintenance Procedures
Establish automated backup procedures to protect your WordPress installation:
#!/bin/bash
# WordPress backup script
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backups/wordpress"
WP_DIR="/var/www/html/wordpress"
DB_NAME="wordpress_db"
DB_USER="wordpress_user"
DB_PASS="your_password"
mkdir -p $BACKUP_DIR
# Backup files
tar -czf $BACKUP_DIR/wp_files_$DATE.tar.gz $WP_DIR
# Backup database
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/wp_db_$DATE.sql
# Keep only last 7 days of backups
find $BACKUP_DIR -type f -mtime +7 -delete
Schedule this script to run daily using cron:
sudo crontab -e
Add this line to run backups at 2 AM daily:
0 2 * * * /path/to/backup_script.sh
Regular maintenance tasks should include updating WordPress core, plugins, and themes, monitoring log files for errors, and reviewing security plugins for potential threats. The official WordPress documentation provides detailed guidance on maintaining WordPress installations and implementing security best practices.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.