Skip to main content
How to Install WordPress on a VPS with Nginx, PHP-FPM and MariaDB - Virtarix Blog

How to Install WordPress on a VPS with Nginx, PHP-FPM and MariaDB

December 6, 2024 · Blog / Technical Guides

This guide installs WordPress with WP-CLI after the Nginx, PHP-FPM, and MariaDB base stack is working. If those services are not installed and verified yet, complete the CMS development base-stack guide first.

The commands below create the WordPress database and user, download WordPress, configure PHP-FPM and Nginx, and connect the domain. Run them from an account with sudo access, keep current backups, and replace every uppercase placeholder with a value for your environment.

Step 1: prepare your VPS environment

Ensure that PHP, NGINX and MariaDB are installed in your development environment.

Create a separate user from the root user for usage and run this command to switch users:

Switch to the WordPress deployment user
su - YOUR_USER

Use the following command to make WP-CLI executable:

Make the WP-CLI Phar executable
chmod +x wp-cli.phar 

Download the WP-CLI Phar with:

Download the WP-CLI Phar
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Terminal downloading WP-CLI and making the command executable

Step 2: set up WP-CLI and configure access

Move the WP-CLI file to an appropriate directory with

Install WP-CLI in the system path
sudo mv wp-cli.phar /usr/local/bin/wp 

You can then use it as the:

Invoke the WP-CLI executable
wp 

Check the WP-CLI version by running:

Display WP-CLI environment information
wp cli info

Terminal showing WP-CLI environment and version information

Log in to MariaDB using

Open MariaDB as the root user
sudo mysql -u root -p 

to proceed with database creation. Enter the root password when prompted.

MariaDB prompt showing a failed and successful WordPress database creation command

Step 3: set up and organize your WordPress database

Execute the SQL command

Create the WordPress database
CREATE DATABASE YOUR_DATABASE; 

to create the database. These commands are case sensitive, so be sure to type them as-is.

MariaDB prompt showing the initial WordPress database command attempt

Grant necessary privileges to the WordPress user with

Grant a local user all database privileges
CREATE USER 'NEW_USER'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON YOUR_DATABASE.* TO 'NEW_USER'@'localhost';
FLUSH PRIVILEGES;

MariaDB prompt showing a GRANT ALL PRIVILEGES query for the WordPress database

Step 4: create and configure the WordPress database

After granting privileges, exit MariaDB by typing EXIT;. Navigate to /var/www/html using:

Change to the WordPress document root
cd /var/www/html

Step 5: prepare the WordPress installation directory

Install and download WP-Core using

Attempt to download WordPress core for a locale
wp core download --locale=YOUR_LOCALE

Please note when downloading WP-Core make sure to adjust the language when installing e.g.

Show WordPress locale download examples
wp core download --locale=en_GB

If permission errors occur, identify your user by typing whoami and adjust permissions for /var/www/html using:

Safety check: Confirm the target and keep a recent backup or snapshot. Preview the affected resources where possible, and document a tested recovery or rollback path before running this command.

Change ownership of the WordPress document root
sudo chown -R YOUR_USER /var/www/html

for the necessary access.

WP-CLI downloading WordPress core files successfully

Step 6: download and install WordPress core files

Once downloaded, execute

Create wp-config.php with database credentials
wp config create --dbname=YOUR_WP_DATABASE --dbuser=YOUR_USER --dbpass=STRONG_PASSWORD --dbhost=localhost 

to set up the wp-config.php configuration file.

WP-CLI confirming creation of the WordPress configuration file

Step 7: run the WordPress configuration command

Run the following command:

Install and configure the WordPress site
wp core install --url="YOUR_DOMAIN_NAME" --title="YOUR_SITE_TITLE" --admin_user="YOUR_USER" --admin_password="ANOTHER_STRONG_PASSWORD" --admin_email="YOUR_EMAIL"

WP-CLI confirming successful WordPress installation

Step 8: configure PHP-FPM for WordPress

Verify the PHP-FPM version you have installed, and update the server configuration file to match this version. Here, we're using PHP 8.3.

Check the status of PHP FastCGI Process Manager with

Attempt to check the PHP-FPM 8.3 service status
systemctl list-unit-files 'php*-fpm.service'

Use the installed PHP-FPM service name in the Nginx socket path and service commands. Return to the base-stack guide if PHP-FPM is not installed.

systemctl status output confirming PHP-FPM is active

If the PHP-FPM service is not running, start it with

Start PHP-FPM 8.3
sudo systemctl start YOUR_PHP_FPM_SERVICE

Enable it to start on boot with

Enable PHP-FPM 8.3 at boot
sudo systemctl enable YOUR_PHP_FPM_SERVICE

Step 9: configure Nginx for WordPress

Configure NGINX by navigating to /etc/nginx/sites-available with:

Change to the Nginx sites-available directory
cd /etc/nginx/sites-available 

Create a new file for your domain using the

Open a new Nginx server block file
sudo nano YOUR_DOMAIN_NAME 

command and add the server configuration.

Create a complete server block with the correct document root, index files, WordPress front-controller fallback, PHP-FPM socket, and protection for hidden files:

Configure the WordPress Nginx server block
server {
    listen 80;
    server_name YOUR_DOMAIN_NAME;
    root /var/www/html;
    index index.php index.html;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/YOUR_PHP_FPM_SOCKET;
    }

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

Save the file after editing.

Nginx site configuration open in Nano

Step 10: review ownership and permissions

Give the web-server account only the write access WordPress actually needs. Avoid leaving the entire document root owned by a personal deployment account or globally writable. Record the chosen owner/group model before enabling the site.

Step 11: add server names to your Nginx configuration

Create a symbolic link from sites-available to sites-enabled running this command:

Enable the Nginx site with a symbolic link
sudo ln -s /etc/nginx/sites-available/YOUR_DOMAIN_NAME /etc/nginx/sites-enabled/

to ensure the configuration loads correctly.

Terminal showing PHP-FPM service output and the Nginx site symlink command

Step 12: test and apply Nginx changes with PHP-FPM

Test the NGINX configuration with

Test the Nginx configuration
sudo nginx -t 

to ensure it works properly.

Nginx configuration test reporting successful syntax and configuration

Apply the verified configuration with sudo systemctl reload nginx. A reload keeps the previous configuration running if the syntax test fails; do not reload until sudo nginx -t passes.

Terminal confirming authentication after restarting Nginx

Step 13: set up DNS records for your VPS domain

At the authoritative DNS provider, add an A record that points the intended hostname to the VPS IPv4 address. Add an AAAA record only when IPv6 is configured and reachable. After DNS resolves, install a TLS certificate using a current method for your environment and verify the served hostname, certificate chain, WordPress front page, and admin login.

Frequently asked questions

What software is required before installing WordPress on a VPS?

Ensure PHP, NGINX, MariaDB, a DBMS, and a web server are installed before starting.

How do I create a database for WordPress?

Log in to MariaDB, execute SQL commands to create a database, and grant user privileges with a password.

What should I do if I encounter permission errors during the installation?

Use the whoami command to identify your user and adjust permissions with chown for proper access.

How do I test and apply NGINX server configuration changes?

Use the command sudo nginx -t to test the NGINX configuration. If there are no errors, apply the changes by restarting NGINX with this command:

Restart Nginx
sudo systemctl restart nginx

How can I connect my domain to the WordPress VPS?

Update DNS settings with your domain provider by adding an A record pointing to your VPS IP address.

Ready to run a WordPress development VPS?

Compare self-managed VPS sizes for WordPress development, staging, and databases with root access, NVMe storage, IPv4 + IPv6 and one snapshot.

VPS S

For small WordPress sites

$ 5 .50 /month
  • 3 cores
  • 6 GB
  • 50 GB NVMe
  • Unlimited
Get It Now
BEST SELLER

VPS M

For growing WooCommerce or blogs

$ 11 .40 /month
  • 6 cores
  • 16 GB
  • 100 GB NVMe
  • Unlimited
Get It Now
Peter French
About the Author Peter Frenchis the Managing Director at Virtarix, with over 17 years in the tech industry. He has co-founded a cloud storage business, led strategy at a global cloud computing leader, and driven market growth in cybersecurity and data protection.