Deploying WordPress on a Linux VPS with Nginx and PHP-FPM

  1. Home
  2. Blog
  3. Deploying WordPress on a Linux VPS with Nginx and...

Running WordPress on your own VPS with Nginx and PHP-FPM gives you full control over the server stack and eliminates the resource contention that makes shared hosting slow under load. Nginx handles concurrent connections efficiently, PHP-FPM manages PHP workers as a separate process pool, and MariaDB provides a fast, well-maintained database engine. This is the same stack used on Arcadia's managed platform.

This guide assumes you have completed the Ubuntu 24.04 initial setup guide and have a non-root user with sudo access. You will also need a domain name pointed at your server's IP address before the Nginx configuration will resolve correctly.

Step 1 - Installing Nginx, PHP, and MariaDB

Start by updating the package list and installing the web server, PHP runtime, and database in a single command:

sudo apt update
sudo apt install nginx php8.3-fpm php8.3-mysql php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip php8.3-gd php8.3-imagick mariadb-server -y

Once complete, Nginx, PHP-FPM, and MariaDB are installed and running. You will configure each of them in the steps that follow.

Step 2 - Securing MariaDB

MariaDB ships with a setup script that removes insecure defaults. Run it before creating any databases:

sudo mysql_secure_installation

Follow the prompts: set a root password, remove anonymous users, disallow remote root login, and remove the test database. Accepting all the recommended options is safe for a typical WordPress installation.

Step 3 - Creating a Database for WordPress

WordPress needs its own database and a dedicated user with access to it. Log into MariaDB as root:

sudo mysql -u root -p

Inside the MariaDB prompt, create the database and user, then grant the necessary permissions:

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strong-password-here';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace strong-password-here with a unique password. Note the database name, username, and password; you will need them in step 6. Your database is ready.

Step 4 - Downloading WordPress

Download the latest WordPress release and extract it into the web root directory. The www-data user needs to own these files so that PHP-FPM can read and write them:

cd /var/www
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
sudo chown -R www-data:www-data wordpress
sudo rm latest.tar.gz

WordPress is now in /var/www/wordpress and owned by the web server user. In the next step, you will point Nginx at this directory.

Step 5 - Configuring Nginx

In this step, you will create an Nginx site configuration that tells it how to serve WordPress. Create a new config file:

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

Paste the following, replacing example.com with your domain:

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

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

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

    location ~ /\.ht {
        deny all;
    }
}

Enable the site and reload Nginx to apply the configuration:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

The nginx -t command tests the configuration before reloading. If it reports a syntax error, fix it before running the reload. Nginx is now configured to serve your WordPress site.

Step 6 - Configuring WordPress

WordPress reads its database connection settings from wp-config.php. Copy the sample file to create it:

cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update the database settings to match the credentials you created in step 3:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'strong-password-here' );
define( 'DB_HOST', 'localhost' );

Save and close the file. WordPress can now connect to the database you created earlier.

Step 7 - Completing the WordPress Install

With the server and files configured, open a browser and visit http://your.server.ip. The WordPress installation wizard will walk you through setting your site title, admin username, and password. Complete the wizard and log in to the WordPress admin panel to confirm everything is working.

Next Steps

You have installed WordPress on Nginx with PHP-FPM and MariaDB, the same stack Arcadia uses on its managed platform. The next steps are to set up SSL with Certbot to serve the site over HTTPS, configure a page cache to avoid generating pages dynamically on every request, and optionally add Redis for object caching to speed up database-heavy operations like WooCommerce.

Related Articles

Guides

How to Set Up a Fresh Ubuntu 24.04 VPS

Step-by-step: configure a fresh Ubuntu 24.04 VPS from first SSH login to a secur...

Guides

Securing Your VPS with UFW and Fail2Ban

How to configure UFW and Fail2Ban on Ubuntu to protect your VPS from port scans...

Guides

Setting Up SSH Key Authentication on Ubuntu

How to set up SSH key authentication on Ubuntu and disable password logins to se...