thelinuxvault blog

Installing WordPress on a LAMP Stack in Ubuntu 24.04

WordPress is the world’s most popular content management system (CMS), powering over 40% of websites globally. It’s flexible, user-friendly, and ideal for everything from personal blogs to enterprise sites. To run WordPress, you need a web server, database, and scripting language—collectively known as a LAMP stack (Linux, Apache, MySQL, PHP).

In this guide, we’ll walk through installing WordPress on a LAMP stack using Ubuntu 24.04 LTS (Long-Term Support), the latest stable release of Ubuntu. Ubuntu 24.04 offers improved security, performance, and support until 2032, making it an excellent choice for hosting. By the end, you’ll have a fully functional WordPress site ready to customize.

2026-02

Table of Contents#

  1. Prerequisites
  2. Setting Up the LAMP Stack
  3. Creating a MySQL Database and User for WordPress
  4. Installing WordPress
  5. Configuring Apache for WordPress
  6. Completing the WordPress Setup via Browser
  7. Testing the Installation
  8. Troubleshooting Common Issues
  9. Conclusion
  10. References

Prerequisites#

Before starting, ensure you have:

  • An Ubuntu 24.04 LTS server (physical, virtual, or cloud-based, e.g., AWS EC2, DigitalOcean Droplet).
  • A user account with sudo privileges (to run administrative commands).
  • A stable internet connection (to download packages).
  • (Optional) A domain name pointing to your server’s IP (for production; skip for local testing).

Setting Up the LAMP Stack#

A LAMP stack is the foundation for hosting WordPress. Let’s install each component step-by-step.

Step 1: Install Apache Web Server#

Apache is a popular open-source web server that handles HTTP requests and serves web content.

  1. Update your system packages (always a good first step to ensure you have the latest software):

    sudo apt update && sudo apt upgrade -y  
  2. Install Apache:

    sudo apt install apache2 -y  
  3. Verify Apache is running:

    sudo systemctl status apache2  

    You should see active (running) in the output.

  4. Enable Apache to start on boot:

    sudo systemctl enable apache2  
  5. Configure the firewall (if using ufw, Ubuntu’s default firewall) to allow HTTP (port 80) and HTTPS (port 443) traffic:

    sudo ufw allow 'Apache Full'  

    Verify the rule with:

    sudo ufw status  
  6. Test Apache: Open a browser and navigate to your server’s public IP (e.g., http://your-server-ip). You’ll see Apache’s default Ubuntu page, confirming Apache is working.

Step 2: Install MySQL Database Server#

MySQL is a relational database management system (RDBMS) that stores WordPress data (posts, users, settings).

  1. Install MySQL Server:

    sudo apt install mysql-server -y  
  2. Verify MySQL is running:

    sudo systemctl status mysql  

    Output should show active (running).

  3. Secure the MySQL installation (critical for security):
    Run the built-in security script to set a root password, remove anonymous users, and disable remote root login:

    sudo mysql_secure_installation  

    Follow the prompts:

    • Press Y to enable the Validate Password Plugin (recommended).
    • Set a strong root password (store this securely!).
    • Answer Y to all remaining questions (remove anonymous users, disallow remote root login, remove test database, reload privileges).
  4. Test MySQL access: Log into the MySQL shell as the root user:

    sudo mysql -u root -p  

    Enter the root password you set earlier. You’ll see the MySQL prompt (mysql>), confirming access. Exit with:

    exit;  

Step 3: Install PHP and Required Extensions#

PHP is a server-side scripting language that processes dynamic content (e.g., WordPress themes/plugins). WordPress requires PHP 7.4 or higher; Ubuntu 24.04 includes PHP 8.3 by default (fully compatible).

  1. Install PHP and essential modules (including MySQL support and WordPress dependencies):

    sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y  
    • libapache2-mod-php: Connects Apache to PHP.
    • php-mysql: Allows PHP to communicate with MySQL.
    • Other modules: Required for WordPress features (e.g., image uploads, XML-RPC, internationalization).
  2. Verify PHP installation:
    Create a test PHP file in Apache’s web root (/var/www/html):

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

    Add this code:

    <?php phpinfo(); ?>  

    Save and exit (Ctrl+O, Enter, Ctrl+X).

  3. Test PHP: In a browser, visit http://your-server-ip/info.php. You’ll see a PHP info page with details about your PHP configuration.

    Note: Delete info.php after testing (it exposes sensitive server info):

    sudo rm /var/www/html/info.php  
  4. Restart Apache to apply PHP changes:

    sudo systemctl restart apache2  

Creating a MySQL Database and User for WordPress#

WordPress needs a dedicated database and user to store its data. Using the root MySQL user is insecure, so we’ll create a limited-privilege user.

  1. Log into MySQL as root:

    sudo mysql -u root -p  
  2. Create a WordPress database (replace wordpress_db with your preferred name):

    CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;  
    • utf8mb4 supports all Unicode characters, including emojis.
  3. Create a MySQL user (replace wp_user and strong_password with your own):

    CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password';  
  4. Grant privileges to the user on the WordPress database:

    GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';  
  5. Flush privileges to apply changes:

    FLUSH PRIVILEGES;  
  6. Exit MySQL:

    exit;  

Installing WordPress#

Now, download and set up the WordPress files.

  1. Navigate to Apache’s web root (or a subdirectory; we’ll use /var/www/wordpress for organization):

    cd /var/www  
  2. Download the latest WordPress tarball from wordpress.org:

    sudo wget https://wordpress.org/latest.tar.gz  
  3. Extract the tarball:

    sudo tar -xvzf latest.tar.gz  

    This creates a wordpress directory with all core files.

  4. Set file ownership (critical for Apache to read/write WordPress files):
    Apache runs as the www-data user, so set ownership to www-data:

    sudo chown -R www-data:www-data /var/www/wordpress/  
  5. Set file permissions (secure but accessible):
    Directories should be 755 (read/execute for all, write for owner), files 644 (read for all, write for owner):

    sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;  
    sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;  
  6. Remove the downloaded tarball (cleanup):

    sudo rm latest.tar.gz  

Configuring Apache for WordPress#

To serve WordPress, we’ll create an Apache virtual host (VH) file. Virtual hosts let you host multiple sites on one server (optional but recommended for organization).

  1. Create a virtual host file for WordPress:

    sudo nano /etc/apache2/sites-available/wordpress.conf  
  2. Add the following configuration (replace your-domain.com with your domain or server IP):

    <VirtualHost *:80>  
        ServerAdmin [email protected]  
        DocumentRoot /var/www/wordpress  
        ServerName your-domain.com  
        ServerAlias www.your-domain.com  
     
        <Directory /var/www/wordpress>  
            AllowOverride All  
            Require all granted  
        </Directory>  
     
        ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log  
        CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined  
    </VirtualHost>  
    • AllowOverride All: Enables .htaccess files (required for WordPress permalinks).
    • ServerName/ServerAlias: Replace with your domain (or skip for local testing, using localhost).
  3. Save and exit (Ctrl+O, Enter, Ctrl+X).

  4. Enable the virtual host and disable Apache’s default site:

    sudo a2ensite wordpress.conf  
    sudo a2dissite 000-default.conf  
  5. Enable the rewrite module (required for WordPress permalinks):

    sudo a2enmod rewrite  
  6. Test Apache configuration for syntax errors:

    sudo apache2ctl configtest  

    If you see Syntax OK, proceed.

  7. Restart Apache to apply changes:

    sudo systemctl restart apache2  

Completing the WordPress Setup via Browser#

Now, finalize WordPress installation through your browser.

  1. Access the WordPress setup page:
    Open a browser and navigate to your server’s IP or domain (e.g., http://your-domain.com or http://localhost if testing locally).

  2. Select your language and click “Continue.”

  3. Enter your database details:

    • Database Name: wordpress_db (the database you created).
    • Username: wp_user (the MySQL user you created).
    • Password: strong_password (the user’s password).
    • Database Host: localhost (default for local MySQL).
    • Table Prefix: wp_ (default; change for security if desired).
      Click “Submit.”
  4. Run the installation:
    Click “Run the Installation” to proceed.

  5. Set up your WordPress site:

    • Site Title: Your site’s name (e.g., “My Tech Blog”).
    • Username: Choose an admin username (avoid “admin” for security).
    • Password: Use a strong, unique password (store it securely!).
    • Your Email: Admin email for notifications.
    • Search Engine Visibility: Check “Discourage search engines from indexing this site” if testing (uncheck later for production).
      Click “Install WordPress.”
  6. Log in:
    After installation, click “Log In” and enter your admin credentials. You’ll land on the WordPress Dashboard—your site is ready!

Testing the Installation#

Verify your WordPress site works:

  • Visit the front end: http://your-domain.com (you’ll see the default WordPress theme).
  • Create a test post: Go to Posts > Add New, write a title/content, and click “Publish.” View it on the front end to confirm it loads.
  • Test permalinks: Go to Settings > Permalinks, select “Post name,” and save changes. Visit a post to ensure the URL (e.g., http://your-domain.com/test-post) works (no 404 errors).

Troubleshooting Common Issues#

1. Apache Fails to Restart#

  • Check for syntax errors: sudo apache2ctl configtest.
  • Ensure no other service uses port 80: sudo lsof -i :80.

2. Database Connection Error#

  • Verify MySQL credentials in wp-config.php (located in /var/www/wordpress).
  • Ensure the MySQL user has privileges:
    sudo mysql -u root -p -e "SHOW GRANTS FOR 'wp_user'@'localhost';"  

3. WordPress Can’t Write Files (e.g., Plugins/Themes)#

  • Confirm file ownership: sudo chown -R www-data:www-data /var/www/wordpress/.
  • Check permissions: sudo ls -la /var/www/wordpress/ (directories should be drwxr-xr-x, files -rw-r--r--).

4. PHP Modules Missing#

  • Reinstall PHP modules: sudo apt install php-curl php-gd ... (repeat the PHP install command).

Conclusion#

You’ve successfully installed WordPress on a LAMP stack in Ubuntu 24.04! You now have a secure, self-hosted WordPress site ready for customization. Next steps:

  • Install a theme (Appearance > Themes).
  • Add plugins (Plugins > Add New).
  • Configure HTTPS with Let’s Encrypt (use certbot for free SSL).
  • Back up your site regularly (e.g., with the UpdraftPlus plugin).

References#