Tutorial: Installing WordPress on Ubuntu with NGINX and MariaDB

WordPress is one of the most popular content management systems (CMS) in the world, and for good reason. It’s user-friendly, customizable, and has a thriving community of developers creating themes and plugins that can extend its functionality. In this tutorial, we’ll show you how to install WordPress on Ubuntu using Nginx as the web server and MariaDB as the database management system.

Prerequisites Before we start, you’ll need a few things:

  • An Ubuntu 22.04+ server
  • A non-root user with sudo privileges
  • Nginx installed and configured
  • MariaDB installed and configured

Step 1: Install PHP

WordPress is built using PHP, so we’ll need to install PHP and a few PHP extensions to run WordPress. To install PHP, run the following command:

sudo apt update
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc

Step 2: Create a Database and User for WordPress

WordPress stores all its data in a database, so we need to create a new database and user for WordPress to use. To create a new database, log in to MariaDB as the root user:

sudo mysql -u root -p

Once you’re logged in, create a new database:


Next, create a new user for WordPress and grant it privileges to the new database:

CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';

Replace ‘password’ with a secure password for the new user.

Step 3: Download and Install WordPress

We’ll download the latest version of WordPress from the official website and extract it to the document root of our Nginx web server:

sudo wget -c http://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz -C /var/www/

After extracting the files, you should have a new directory called ‘wordpress’ in your document root.

Step 4: Configure Nginx for WordPress

We need to configure Nginx to serve WordPress. Create a new Nginx server block file for WordPress:

sudo nano /etc/nginx/sites-available/wordpress

Copy and paste the following configuration into the file:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/wordpress;
    index index.php;

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

Replace ‘yourdomain.com’ with your domain name.

Save and exit the file, then create a symbolic link to enable the server block:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

Step 5: Test the Nginx Configuration and Restart Nginx

Test the Nginx configuration to make sure there are no syntax errors:

sudo nginx -t

If there are no errors, restart Nginx:

sudo systemctl restart nginx

Step 6: Complete the WordPress Installation

Now that everything is set up, we can complete the WordPress installation by accessing our server through a web browser. Navigate to ‘http://yourdomain.com‘ in your web browser, and you should see the WordPress installation screen.

Select your language, then enter the database details you created earlier. For the database host, enter ‘localhost’, the database name ‘wordpress’, the username ‘wordpressuser’, and the password you chose earlier. Leave the table prefix as ‘wp_’ unless you have a good reason to change it.

Next, enter a title and username for your new WordPress site, as well as a secure password. Click ‘Install WordPress’ to finish the installation.

Congratulations, you have successfully installed WordPress on Ubuntu using Nginx and MariaDB! You can now log in to the WordPress admin panel to customize your site and start creating content.

Leave a Reply

Scroll to top