BLOG POSTS
Installing WordPress on Ubuntu 24 with a LAMP Stack

Installing WordPress on Ubuntu 24 with a LAMP Stack

Setting up WordPress on Ubuntu 24 with a LAMP stack is one of those classic sysadmin rites of passage that never gets old. Whether you’re spinning up your first blog, deploying a client site, or just want to understand how the web really works under the hood, this guide will walk you through every step of building a rock-solid WordPress installation from scratch. We’ll cover the entire LAMP (Linux, Apache, MySQL, PHP) stack setup, tackle common gotchas that trip up newcomers, and throw in some pro tips that’ll make your life easier down the road. By the end, you’ll have a production-ready WordPress instance and the knowledge to troubleshoot issues like a seasoned server wrangler.

How Does the LAMP Stack Work with WordPress?

Think of LAMP as the four-legged stool that keeps your WordPress site standing. Linux provides the foundation operating system, Apache serves up your web pages to visitors, MySQL stores all your posts and user data, and PHP processes the dynamic content that makes WordPress tick. When someone visits your site, Apache receives the request, PHP executes the WordPress code, MySQL delivers the content from the database, and Apache sends the final HTML back to the visitor’s browser.

The beauty of this setup is its modularity – each component can be tweaked, optimized, or even replaced independently. Need better performance? Tune your MySQL queries. Want more security? Harden your Apache configuration. It’s like having a Swiss Army knife for web hosting.

Ubuntu 24 brings some sweet improvements to this classic stack, including PHP 8.3 by default, better systemd integration, and enhanced security features that make your server more resistant to common attacks. Plus, the package management is smooth as butter compared to compiling everything from source (trust me, I’ve been there).

Step-by-Step LAMP Stack Installation

Alright, let’s get our hands dirty. I’m assuming you’ve got a fresh Ubuntu 24 server ready to go. If you need a VPS to practice on, grab one here, or if you’re planning something bigger, check out their dedicated servers.

Initial Server Setup

First things first – update your system and grab the essentials:

sudo apt update && sudo apt upgrade -y
sudo apt install curl wget unzip software-properties-common -y

Installing Apache

Apache is your web server – the front door to your site. Let’s install it and get it running:

sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2

Test it by hitting your server’s IP address in a browser. You should see the Apache2 Ubuntu default page. If you’re on the server itself, try:

curl localhost

Pro tip: Enable the rewrite module now – WordPress needs it for pretty permalinks:

sudo a2enmod rewrite
sudo systemctl restart apache2

Installing MySQL

Time for the database. MySQL 8.0 comes with Ubuntu 24, and it’s a solid choice:

sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql
sudo mysql_secure_installation

The secure installation script will ask you a bunch of questions. Here’s what I recommend:

  • Set a strong root password (obviously)
  • Remove anonymous users (yes)
  • Disallow root login remotely (yes, unless you have a specific need)
  • Remove test database (yes)
  • Reload privilege tables (yes)

Installing PHP

PHP 8.3 is what we’re after, along with the modules WordPress loves:

sudo apt install php php-mysql php-curl php-gd php-xml php-xmlrpc php-soap php-intl php-zip php-mbstring libapache2-mod-php -y
sudo systemctl restart apache2

Test PHP with a quick info file:

echo "" | sudo tee /var/www/html/info.php

Visit `http://your-server-ip/info.php` to see if PHP is working. Don’t forget to remove this file afterward – it’s a security risk:

sudo rm /var/www/html/info.php

WordPress Installation and Configuration

Creating the Database

Let’s set up a dedicated database and user for WordPress:

sudo mysql -u root -p

Inside MySQL, run these commands (replace `your_password` with something secure):

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Downloading and Configuring WordPress

Grab the latest WordPress and set it up:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Now comes the fun part – configuration. First, get your security keys:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

Copy the output and edit your wp-config.php:

nano /tmp/wordpress/wp-config.php

Update these sections:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');

// Paste your security keys here, replacing the dummy values

Add this handy line to handle file permissions better:

define('FS_METHOD', 'direct');

Setting Up File Permissions

Copy WordPress to your web directory and fix permissions:

sudo cp -a /tmp/wordpress/. /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/ -type f -exec chmod 640 {} \;

Apache Virtual Host Configuration

Let’s create a proper virtual host instead of using the default:

sudo nano /etc/apache2/sites-available/wordpress.conf

Add this configuration (replace `your-domain.com` with your actual domain):

<VirtualHost *:80>
    ServerAdmin admin@your-domain.com
    ServerName your-domain.com
    ServerAlias www.your-domain.com
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    <Directory /var/www/html/>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Enable the site and disable the default:

sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2

Real-World Examples and Troubleshooting

Common Issues and Solutions

Here’s where things get interesting. I’ve seen these problems more times than I can count:

Problem Symptoms Solution
Permission Issues Can’t upload files, install plugins Check ownership: sudo chown -R www-data:www-data /var/www/html/
Database Connection Error WordPress can’t connect to MySQL Verify credentials in wp-config.php, check MySQL service status
404 Errors on Posts Homepage works, posts don’t Enable mod_rewrite: sudo a2enmod rewrite
PHP Memory Limit White screen, plugin crashes Increase memory_limit in /etc/php/8.3/apache2/php.ini

Performance Comparison

Let’s talk numbers. A basic LAMP stack on a 1GB VPS can typically handle:

  • 50-100 concurrent users with proper caching
  • 500-1000 page views per hour for a typical WordPress blog
  • Database queries under 100ms for most operations

Compare this to other stacks:

Stack Memory Usage Setup Complexity Performance WordPress Compatibility
LAMP Medium Low Good Excellent
LEMP (Nginx) Low Medium Better Good
Docker WordPress High Medium Variable Excellent

Security Hardening

Don’t skip this part – a default installation is like leaving your front door wide open. Here are some essential hardening steps:

# Hide Apache version
sudo nano /etc/apache2/conf-available/security.conf
# Set ServerTokens Prod and ServerSignature Off

# Install fail2ban for brute force protection
sudo apt install fail2ban -y

# Set up a basic firewall
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable

For WordPress-specific security, add this to your wp-config.php:

// Disable file editing in admin
define('DISALLOW_FILE_EDIT', true);

// Force SSL (if you have HTTPS set up)
define('FORCE_SSL_ADMIN', true);

// Limit login attempts
define('WP_LOGIN_ATTEMPTS', 3);

Advanced Automation and Scripting

Here’s where the real magic happens. Once you’ve done this setup a few times, you’ll want to automate it. I’ve created a quick deployment script that handles the entire LAMP + WordPress installation:

#!/bin/bash
# wordpress-auto-install.sh

DB_NAME="wordpress"
DB_USER="wordpressuser"
DB_PASS=$(openssl rand -base64 32)
WP_ADMIN_USER="admin"
WP_ADMIN_PASS=$(openssl rand -base64 16)
DOMAIN="example.com"

# Update system
apt update && apt upgrade -y

# Install LAMP
apt install apache2 mysql-server php php-mysql php-curl php-gd php-xml php-xmlrpc php-soap php-intl php-zip php-mbstring libapache2-mod-php -y

# Configure Apache
a2enmod rewrite
systemctl restart apache2

# Secure MySQL and create database
mysql -e "CREATE DATABASE ${DB_NAME} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
mysql -e "CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASS}';"
mysql -e "GRANT ALL ON ${DB_NAME}.* TO '${DB_USER}'@'localhost';"
mysql -e "FLUSH PRIVILEGES;"

# Download and configure WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
cp wordpress/wp-config-sample.php wordpress/wp-config.php

# Update wp-config.php
sed -i "s/database_name_here/${DB_NAME}/" wordpress/wp-config.php
sed -i "s/username_here/${DB_USER}/" wordpress/wp-config.php
sed -i "s/password_here/${DB_PASS}/" wordpress/wp-config.php

# Copy to web directory
cp -a wordpress/. /var/www/html/
chown -R www-data:www-data /var/www/html/

echo "WordPress installed successfully!"
echo "Database: ${DB_NAME}"
echo "DB User: ${DB_USER}"
echo "DB Pass: ${DB_PASS}"

This opens up possibilities for:

  • Automated staging environment creation
  • One-click client site deployments
  • Development environment provisioning with Vagrant or Docker
  • CI/CD pipeline integration

Integration with Modern Tools

Your LAMP stack doesn’t exist in isolation. Here are some killer integrations:

Monitoring and Logging

# Install htop for system monitoring
sudo apt install htop iotop -y

# Set up log rotation for WordPress
sudo nano /etc/logrotate.d/wordpress

Backup Automation

Set up automated backups with a simple cron job:

# Create backup script
cat > /home/ubuntu/backup-wordpress.sh << 'EOF'
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backups"
mkdir -p $BACKUP_DIR

# Backup database
mysqldump -u wordpressuser -p'your_password' wordpress > $BACKUP_DIR/wp_db_$DATE.sql

# Backup files
tar -czf $BACKUP_DIR/wp_files_$DATE.tar.gz /var/www/html/

# Keep only last 7 days of backups
find $BACKUP_DIR -name "wp_*" -mtime +7 -delete
EOF

chmod +x /home/ubuntu/backup-wordpress.sh

# Add to crontab (daily at 2 AM)
echo "0 2 * * * /home/ubuntu/backup-wordpress.sh" | crontab -

Performance Optimization

Install and configure caching for better performance:

# Install Redis for object caching
sudo apt install redis-server php-redis -y

# Install Apache modules for compression
sudo a2enmod deflate
sudo a2enmod expires
sudo a2enmod headers
sudo systemctl restart apache2

Interesting Facts and Unconventional Use Cases

Here’s some geeky trivia that might blow your mind:

  • WordPress powers over 40% of all websites on the internet – that’s roughly 810 million sites
  • The LAMP stack has been around since 1998, making it older than Google
  • A properly optimized LAMP stack can serve over 10,000 requests per second on modern hardware
  • Netflix used Apache (part of LAMP) to serve their early streaming platform before moving to microservices

Some unconventional uses I’ve seen:

  • Using WordPress as a headless CMS for mobile apps (with WP REST API)
  • Building internal company dashboards with custom WordPress installations
  • Creating API endpoints for IoT devices using WordPress plugins
  • Running e-learning platforms with WordPress + custom plugins

Troubleshooting Common Gotchas

Let me save you some hair-pulling with these common issues:

The “White Screen of Death”

Usually a PHP error. Enable debugging in wp-config.php:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Check `/var/www/html/wp-content/debug.log` for clues.

MySQL Connection Issues

Test your database connection manually:

mysql -u wordpressuser -p -h localhost wordpress

If this fails, your wp-config.php credentials are wrong.

Apache Not Starting

Check the error logs:

sudo journalctl -u apache2.service
tail -f /var/log/apache2/error.log

Usually it’s a syntax error in your virtual host configuration.

Related Tools and Utilities

Your LAMP toolkit isn’t complete without these utilities:

  • phpMyAdmin: Web-based MySQL administration (official site)
  • WP-CLI: Command-line interface for WordPress (wp-cli.org)
  • Composer: PHP dependency manager for custom development
  • Let’s Encrypt Certbot: Free SSL certificates
  • Adminer: Lightweight alternative to phpMyAdmin

Install WP-CLI for command-line WordPress management:

curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/v2.8.1/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

# Test it
wp --info --allow-root

Conclusion and Recommendations

Setting up WordPress on Ubuntu 24 with a LAMP stack isn’t just about getting a website running – it’s about understanding the fundamental building blocks of the modern web. You’ve just built something that can scale from a personal blog to a site serving millions of visitors (with the right optimizations, of course).

When to use this setup:

  • You want full control over your hosting environment
  • You need custom PHP configurations or modules
  • You’re building multiple WordPress sites on one server
  • You want to learn server administration skills
  • Budget is a constraint (VPS hosting is incredibly affordable)

When to consider alternatives:

  • You need maximum performance (consider LEMP with Nginx)
  • You want easier scaling (look into managed WordPress hosting)
  • You have complex deployment requirements (Docker might be better)
  • You’re not comfortable with command-line administration

The beauty of what you’ve built is its flexibility. You can now experiment with different caching solutions, try out new PHP versions, or even convert it to a development environment for testing themes and plugins. Plus, the skills you’ve learned here transfer directly to managing any Linux server.

Remember to keep your system updated, monitor your logs, and always have a backup strategy. The LAMP stack has been battle-tested for decades, but like any system, it needs regular maintenance to stay secure and performant.

Whether you’re hosting this on a VPS for testing or deploying it on a dedicated server for production, you now have the foundation to build virtually anything on the web. Happy coding!



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.

Leave a reply

Your email address will not be published. Required fields are marked