linuxenabled.com

How to install WordPress on Ubuntu 24.04 with Apache, MariaDB, PHP 8.3 (LAMP)

Introduction

In this tutorial, you’ll learn how to install WordPress on Ubuntu 24.04 using Apache, MariaDB, and PHP 8.3 (the LAMP stack). WordPress is the most widely used Content Management System (CMS) in the world, powering over one-third of all websites today. Thanks to PHP 8.3 being included in the official Ubuntu 24.04 repositories, WordPress runs reliably and performs excellently on this modern Linux setup. Whether you’re launching a personal blog, a business website, or a full-featured content platform, this guide will walk you through the complete process step by step.

Prerequisites:

  1. Before you begin, make sure you have the following:
  2. A remote server running Ubuntu 24.04.
  3. A registered domain name so visitors can access your website using a human-readable URL. I registered my domain with Namecheap because of its competitive pricing and lifetime free WHOIS privacy protection.
  4. A fully installed and configured LAMP stack (Apache, MariaDB, and PHP 8.3) on Ubuntu 24.04.

Step 1: Download WordPress

Start by connecting to your Ubuntu 24.04 server via SSH, then update the system to ensure all existing packages are up to date:

sudo apt update && sudo apt upgrade -y

Next, visit the official WordPress download page at wordpress.org and download the ZIP archive. To get the direct download URL, right-click the Download WordPress button and select Copy link address. From your server’s command line, use wget with the copied link to download WordPress:

wget https://wordpress.org/latest.zip

Before extracting the archive, make sure the unzip utility is installed:

sudo apt install unzip -y

Create the web root directory (if it doesn’t already exist):

sudo mkdir -p /var/www/

Now extract the WordPress archive into /var/www/:

sudo unzip latest.zip -d /var/www/

The -d option specifies the destination directory. This will extract the WordPress files into /var/www/wordpress. To keep things organized—especially if you plan to host multiple websites—it’s a good idea to rename the WordPress directory to match your domain name. Replace example.com with your actual domain:

sudo mv /var/www/wordpress /var/www/example.com

Your WordPress files are now neatly placed and ready for the next configuration steps

Step 2: Create a Database and User for Your WordPress Site

Log in to the MariaDB shell as the root user by running the following command:
sudo mysql -u root
Once logged in, create a new database for your WordPress site. In this example, the database is named wordpress, but you can choose any name you prefer, such as your site’s name. Be sure to include the semicolon at the end of the command.
CREATE DATABASE wordpress;
Next, create a dedicated database user for WordPress and grant it full privileges on the WordPress database. Replace wpuser and your-password with a secure username and password of your choice.
GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost IDENTIFIED BY 'your-password';
Finally, reload the privilege tables to apply the changes, then exit the MariaDB shell.
FLUSH PRIVILEGES;
EXIT;
Your WordPress database and user are now ready for the next configuration step.

Step 3: Setup and Configure WordPress

Navigate to your WordPress installation directory:
cd /var/www/example.com/
Copy the sample configuration file and rename it to wp-config.php, which WordPress uses for database and site settings:
sudo cp wp-config-sample.php wp-config.php
Next, open the configuration file using a command-line text editor such as Nano:
sudo nano wp-config.php
Locate the following lines in the file and replace the placeholder values with the database name, username, and password you created in the previous step:
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

By default, WordPress uses wp_ as the table prefix for all database tables. For better security, it’s strongly recommended to change this to a unique, random string, for example:
$table_prefix = '5833g_';
Save and close the file. In Nano, press Ctrl + O, then Enter to save, and Ctrl + X to exit. Finally, set the Apache user (www-data) as the owner of the WordPress directory so the web server has the correct permissions:
sudo chown www-data:www-data /var/www/example.com/ -R
Your WordPress configuration is now complete, and the site is ready for the next setup step.

Step 4: Create an Apache Virtual Host file for WordPress

Create an Apache virtual host file for your WordPress site in the /etc/apache2/sites-available/ directory by running the following command:

sudo nano /etc/apache2/sites-available/example.com.conf

Add the configuration below to the file, replacing example.com with your actual domain name. Make sure you have already created the appropriate A records for your domain in your DNS manager.

    ServerName www.example.com
    ServerAlias example.com

    DocumentRoot /var/www/example.com

    # Enable .htaccess support (required for WordPress permalinks)
    <Directory "/var/www/example.com">
        AllowOverride All
    

    ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
    CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined


Save and close the file, then test the Apache configuration to ensure there are no syntax errors:

sudo apache2ctl configtest

If the output shows “Syntax OK”, enable the new virtual host:

sudo a2ensite example.com.conf

Reload Apache to apply the changes:

sudo systemctl reload apache2

Once your domain’s A record is correctly set, open your web browser and visit:

example.com

or directly access the installer at:

example.com/wp-admin/install.php

You should now see the WordPress installation wizard. Select your preferred language to continue with the setup.

Step 5: Enable HTTPS

Scroll to Top