How to Install WordPress on Ubuntu 24.04 : A Step-by-Step Guide

Requirements to Install WordPress on Ubuntu 24.04

Before diving into the installation process, ensure you have the following prerequisites in place:

  • A Server or Virtual Machine Running Ubuntu 24.04
    You’ll need a server or virtual machine with Ubuntu 24.04 installed. This will serve as the foundation for hosting your WordPress site.
  • Root User or a User with Sudo Privileges 
    Administrative access is required to install and configure the necessary software. Ensure you are either logged in as the root user or have a user account with sudo privileges.
  • A domain name : EG “www.example.com”

Kindly watch videos on YouTube on how to add your domain name to cloudflare. Once your domain name is on cloudflare, create an “A” Record & a “CNAME” Record.

The A Record is your root domain pointing to your Ubuntu server ip. The CNAME is “www” pointing to your domain.

Please use this image as a guide.

Before You Begin

Switch to the Root User

To execute administrative commands, switch to the root user if you’re not already logged in as root.

To switch to root or become root user, execute the following command:

sudo su

Step 1.

Confirm The Operating System & Version By Running the next command

The command below retrieves detailed information about the operating system and its version. It checks the contents of the `/etc/*release` files, which store distribution-specific metadata such as the OS name, version, and codename. This ensures that the system meets the necessary requirements before proceeding with the WordPress installation.

cat /etc/*release

Step 2.

System Update

The commands below update the system’s package list and upgrade installed packages to their latest versions. These commands should be run individually: 

apt update – Refreshes the local package index to ensure access to the latest software versions. 
apt upgrade – Installs available updates for all installed packages, improving security, stability, and compatibility. 

Running these commands ensures your system is fully updated before proceeding with the WordPress installation.

apt install && sudo apt upgrade
apt update
apt upgrade

Step 3.

Install Nginx Webserver

The command below installs the Nginx web server, which will serve as the primary web server for hosting the WordPress site. 

1. `apt install nginx` – Installs Nginx from the official Ubuntu repositories. 

Once installed, Nginx runs as a background service, ready to handle HTTP requests. This step ensures your server is equipped to deliver web pages efficiently.

apt install nginx

To start the nginx service and to enable the nginx service to start when the system reboots, issue the following command

The commands below ensure that the Nginx web server is running and will automatically start after a system reboot. 

1. `systemctl enable nginx` – Enables Nginx to start on boot, ensuring that the web server runs automatically whenever the system restarts. 
2. `systemctl start nginx` – Starts the Nginx service immediately, allowing it to begin serving web pages. 

These steps are essential to maintain uptime and ensure the web server remains operational after reboots.

systemctl enable nginx
systemctl start nginx

To check if nginx webservice service is successfully running on the server, issue the following command.

The command below checks the current status of the Nginx web server service. 

– `systemctl status nginx` – Displays detailed information about the Nginx service, including if it is active (running), inactive, or failed

If Nginx is running successfully, the output should indicate an active (running) status. If not, troubleshooting may be required to resolve any errors preventing it from starting.

systemctl status nginx

Step 4.

PHP Installation

The command below installs PHP and its essential extensions, which are required for WordPress to function properly. 

This command includes: 
php-cli – Command-line interface for PHP. 
php-fpm – FastCGI Process Manager, needed for Nginx to process PHP scripts. 
php-mysqli – MySQL database support for PHP. 
php-mbstring, php-xml, php-curl, php-zip, php-gd, php-intl – Required for various WordPress features, including media uploads, multilingual support, and API calls. 

Installing these extensions ensures that WordPress runs smoothly with all necessary dependencies.

apt install php php-cli php-common php-imap php-fpm php-snmp php-xml php-zip php-mbstring php-curl php-mysqli php-gd php-intl

To check the Installed PHP Version, issue the following command

The command below checks the currently installed PHP version on the system. 

This will display details such as: 
– The PHP version number (e.g., PHP 8.3.0). 
– The build date and additional configuration details. 

Verifying the PHP version ensures that the installed version meets the minimum requirements for WordPress and other web applications.

php -v

Step 5.

MariaDB Database Installation

The command below installs MariaDB, a popular open-source database management system used by WordPress. 

MariaDB is a drop-in replacement for MySQL, providing similar functionality with improved performance and security. Installing this package ensures that your server can store and manage WordPress database content efficiently.

apt install mariadb-server

To start the mariadb server service and to enable Mariadb Server service to run on system reboot, Issue the following commands.

The commands below manage the MariaDB service, ensuring it starts automatically and runs correctly: 

1. `systemctl enable mariadb` 
Configures MariaDB to start automatically whenever the system reboots. 

2. `systemctl start mariadb` 
Starts the MariaDB service immediately. 

3. `systemctl status mariadb` 
Checks the current status of MariaDB, displaying whether it’s active and running. 

Running these commands ensures that the database service is always available for WordPress.

systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb

Step 6.

MariaDB Database Configuration

Now that MariaDB is installed and running, we need to create a database and a user for WordPress. This will allow WordPress to store its data securely.

Follow these steps carefully:

1. Log in to the MariaDB console
Type the following command and press Enter to access the MariaDB shell: 

mysql -u root

This will open the MariaDB shell, where you can enter database commands.

2. Run the following commands all at once 
Copy and paste the entire block below into the MariaDB shell. Before running, replace `ExampleUsername` with your preferred database username and `ExamplePassword` with a strong password of your choice: 

create user 'ExampleUsername'@'localhost' identified by 'ExamplePassword';
create database wordpress;
grant all privileges on wordpress.* to 'ExampleUsername'@'localhost';
flush privileges;
exit;

– This will:
     – Create a new database user.
     – Create a database named wordpress.
     – Grant the user full access to the WordPress database.
     – Apply the changes and exit MariaDB.

Once this is done, the database is fully set up for WordPress.

Step 7.

Download and Install WordPress On Ubuntu 24.04

Now, we need to download and extract the latest version of WordPress. The WordPress files will be placed inside Nginx’s root directory, which is where Nginx serves website files from.

Run both commands below individually. Note that after you’ve CD into tmp, if your internet goes off and you have to start from where you stopped, you have to CD back into tmp else there would be implications

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

Download unzip & unzip the latest.zip in nginx root directory. Nginx root directory is where we keep the wordpress files so that when someone access our sites. nginx will serve the files from this directory.

apt install unzip
unzip latest.zip -d /var/www/

To ensure that Nginx can properly serve WordPress files, we need to set the correct ownership of the extracted files.

chown -R www-data:www-data /var/www/wordpress/

Now that we have created a database and a user for WordPress, we need to configure WordPress to use these credentials.

Steps:

1. Rename the Sample Configuration File
WordPress provides a sample configuration file named `wp-config-sample.php`. 
We rename it to `wp-config.php` so WordPress can recognize and use it.

Copy and paste the command below

mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

2. Edit the Configuration File
We use `nano` to open `wp-config.php` and modify the database details.

nano /var/www/wordpress/wp-config.php

3. Update the Database Credentials

Replace `’wordpress’` with the actual database name you created. If you used wordpress previously leave it as wordpress

Replace `’ExampleUsername’` with the database user you created. 

Replace `’ExamplePassword’` with the password you assigned to that user.

DONT COPY THIS. THIS IS A SAMPLE OF WHAT YOU WOULD SEE AFTER RUNNING THE PREVIOUS COMMAND. All you need do is edit as explained above

👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇

define( 'DB_NAME', 'wordpress' );
/** Database username */
define( 'DB_USER', 'ExampleUsername' );
/** Database password */define( 'DB_PASSWORD', 'ExamplePassword' );

4. Save and Exit
Press `Ctrl + O` to save changes. 
Press `Ctrl + X` to exit the nano editor.

These changes allow WordPress to connect to the database and store content dynamically.

Step 8.

WordPress Nginx Configuration

To ensure that Nginx serves WordPress correctly, we need to create a configuration file specifically for WordPress.

Steps:

Open the Configuration File for Editing
We would create a new file called `wordpress.conf` inside the Nginx configuration directory.

nano /etc/nginx/conf.d/wordpress.conf

Copy and paste the complete code snippet below
Make sure to change my domain which is thetechsavage, to your own domain name..

Once you’ve pasted

Press `Ctrl + O` to save changes. 
Press `Ctrl + X` to exit the nano editor.

server {
listen 80;
   server_name thetechsavage.org.ng www.thetechsavage.org.ng;

   root /var/www/wordpress;
   index index.php;

   server_tokens off;

   access_log /var/log/nginx/wordpress_access.log;
   error_log /var/log/nginx/wordpress_error.log;

   client_max_body_size 64M;

location / {
   try_files $uri $uri/ /index.php?$args;
}

   location ~ \.php$ {
      fastcgi_pass  unix:/run/php/php8.3-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi.conf;
    }
}

After saving the Nginx configuration file, we need to test if the syntax is correct before restarting the service.

Steps:

1. Test the Configuration
   – Run `nginx -t` to check for syntax errors.
   – If everything is set up correctly, you should see a message: 
     “nginx: configuration file /etc/nginx/nginx.conf test is successful”

nginx -t

2. Restart Nginx
   – If the test is successful, restart Nginx to apply the changes.

systemctl restart nginx

This ensures that our WordPress site is properly configured and Nginx serves it without errors.

Step 9.

Final Installation Steps through browser

Now that we have completed the server-side setup, we need to finalize the WordPress installation through a web browser.

1. Access Your WordPress Site
   – Open a web browser and enter your server’s IP address or domain name: 
     – `http://10.110.10.10` (Replace with your actual server IP) 
     – `http://www.example.com` (Replace with your domain name)

2. Follow the On-Screen Instructions
   – Choose your language.
   – Enter the database name, username, and password you configured earlier.
   – Set up an admin username and password for your WordPress login.

3. Complete Installation
   – Click on Install WordPress and wait for the process to finish.
   – Once done, you can log in at `http://www.example.com/wp-admin` to start managing your website.

Step 10.

Securing WordPress with Let’s Encrypt SSL Certificate

To ensure your WordPress site is secure and accessible over HTTPS, we will install a free SSL certificate using Let’s Encrypt.

1. Install Certbot
   – Certbot is a tool that automatically obtains and renews SSL certificates for your website.
   – We also install the Nginx plugin, which helps configure the certificate for Nginx automatically.

sudo apt install certbot python3-certbot-nginx

2. Obtain and Apply the SSL Certificate
   – Replace `thetechsavage.org.ng` with your actual domain name.
   – Certbot will generate and install the SSL certificate, updating the Nginx configuration for HTTPS.

sudo certbot --nginx -d thetechsavage.org.ng -d www.thetechsavage.org.ng

3. Verify Installation
   – Once the process is complete, try accessing your site using `https://www.yourdomain.com`. 
   – Your browser should now show a secure lock icon, confirming the SSL certificate is active.

Step 11.

Redirect www to non www

To redirect all www traffic to the non-www version (https://thetechsavage.org.ng), you need to modify your Nginx configuration. Follow these steps:

Step 1: Create a Redirect Server Block

Edit your Nginx configuration:

nano /etc/nginx/conf.d/wordpress.conf

Replace your existing configuration with the following: I.E clear every thing and replace with what’s below

To clear Press `Ctrl + K` repeatedly till every thing is cleared. Once cleared paste the below code block. Remember to replace my url with yours.

# Redirect www to non-www (HTTP and HTTPS)
server {
    listen 80;
    listen [::]:80;
    server_name www.thetechsavage.org.ng;
    return 301 https://thetechsavage.org.ng$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.thetechsavage.org.ng;

    ssl_certificate /etc/letsencrypt/live/thetechsavage.org.ng/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/thetechsavage.org.ng/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    return 301 https://thetechsavage.org.ng$request_uri;
}

server {
    listen 80;
    listen [::]:80;
    server_name thetechsavage.org.ng;
    return 301 https://thetechsavage.org.ng$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name thetechsavage.org.ng;

    root /var/www/wordpress;
    index index.php;

    server_tokens off;

    access_log /var/log/nginx/wordpress_access.log;
    error_log /var/log/nginx/wordpress_error.log;

    client_max_body_size 64M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi.conf;
    }

    ssl_certificate /etc/letsencrypt/live/thetechsavage.org.ng/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/thetechsavage.org.ng/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

Press `Ctrl + O` to save changes. 
Press `Ctrl + X` to exit the nano editor.

Test Nginx Configuration

Run the following command to check if the syntax is correct:

nginx -t

You should see test is successful. If there are any errors, fix them before proceeding.

Restart Nginx

Apply the changes by restarting Nginx:

systemctl restart nginx

Now, all traffic from https://www.thetechsavage.org.ng will be automatically redirected to https://thetechsavage.org.ng.

Step 12.

Fixing Too Many Redirect Error

If you go to your site and it tells you

The webpage at https://www.thetechsavage.org.ng/ could not be loaded because:
net::ERR_TOO_MANY_REDIRECTS

The ERR_TOO_MANY_REDIRECTS error means that your Nginx configuration is causing an infinite loop of redirections. Let’s fix this by making sure there’s a proper redirection setup.

Step 1: Fix the Nginx Configuration

Open your Nginx configuration file:

nano /etc/nginx/conf.d/wordpress.conf

Like before clear every content

To clear Press `Ctrl + K` repeatedly till every thing is cleared. Once cleared paste the below code block. Remember to replace my url with yours.

# Redirect www to non-www (HTTP and HTTPS)
server {
    listen 80;
    listen [::]:80;
    server_name www.thetechsavage.org.ng;
    return 301 https://thetechsavage.org.ng$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.thetechsavage.org.ng;

    ssl_certificate /etc/letsencrypt/live/thetechsavage.org.ng/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/thetechsavage.org.ng/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    return 301 https://thetechsavage.org.ng$request_uri;
}

server {
    listen 80;
    listen [::]:80;
    server_name thetechsavage.org.ng;
    return 301 https://thetechsavage.org.ng$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name thetechsavage.org.ng;

    root /var/www/wordpress;
    index index.php;

    server_tokens off;

    access_log /var/log/nginx/wordpress_access.log;
    error_log /var/log/nginx/wordpress_error.log;

    client_max_body_size 64M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi.conf;
    }

    ssl_certificate /etc/letsencrypt/live/thetechsavage.org.ng/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/thetechsavage.org.ng/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

Press `Ctrl + O` to save changes. 
Press `Ctrl + X` to exit the nano editor.

Step 2: Clear WordPress Redirection Settings

1. Access the WordPress Database:

mysql -u root -p

2. Select the WordPress Database:

USE wordpress;

3. Check WordPress URL Settings:

SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');

4. Ensure it is set to the non-www version:

UPDATE wp_options SET option_value = 'https://thetechsavage.org.ng' WHERE option_name IN ('siteurl', 'home');

5. Exit MySQL:

EXIT;

Step 3: Restart Nginx

nginx -t && systemctl restart nginx

This setup ensures: ✅ www.thetechsavage.org.ng always redirects to thetechsavage.org.ng.
✅ WordPress is correctly set up for the non-www version.

0 Shares:
Leave a Reply

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

You May Also Like
Read More

What Is Canva?

What is Canva? A Comprehensive Guide Canva is a powerful online design tool that allows users to create…
Read More

HOW TO NAPSTERNETV

Hello and welcome to TheTechSavage What is NapsternetV NapsternetV is a VPN (Virtual Private Network) container whete vpn…
Read More

HOW TO SSH CUSTOM

Hello and welcome to TheTechSavage What is SSH Custom SSH Custom is a VPN (Virtual Private Network) container…