Skip to content
Wallet live · USDT TRC20 · USDT BEP20 · BTC · ETH · SOL · XMR Free SSL · Malware scan · Instant image 24/7 desk · @rexahost
RexaHostRexaHost

Web Hosting

How to Install WordPress on a VPS (Nginx, PHP and MariaDB)

· 6 min read

How to Install WordPress on a VPS (Nginx, PHP and MariaDB)

A complete, beginner-friendly guide to installing WordPress on your own Ubuntu VPS with Nginx, PHP-FPM and MariaDB, then securing it with HTTPS, caching and sensible hardening.

Key takeaways

  • A LEMP stack (Linux, Nginx, MariaDB, PHP-FPM) runs WordPress fast and efficiently on a VPS.
  • Secure the server first: sudo user, SSH keys, firewall and updates.
  • Create a dedicated database and user for WordPress with a strong password.
  • Add free HTTPS with Certbot and enable caching for speed.
  • Plan backups and updates from day one, because on a VPS they are your job.

Installing WordPress on your own VPS gives you full control over performance, PHP settings and security, and lets you host several sites on one server. It takes about 30 to 45 minutes the first time. This guide uses Ubuntu 24.04 with Nginx, PHP-FPM and MariaDB, a popular and efficient combination.

Before you start: VPS or shared hosting?

If you want WordPress without managing a server, shared hosting is simpler: Cloud Grow ($3.58 a month) includes cPanel, LiteSpeed, free SSL and daily backups for up to five sites. Choose a VPS when you need more resources, custom configuration or root access. Our shared vs VPS guide helps you decide.

What you need

  • A VPS with Ubuntu 24.04. VPS Basic (1 vCPU, 2 GB RAM, 60 GB NVMe, $5.98) suits one or two sites; VPS Pro (2 vCPU, 4 GB, $11.58) suits WooCommerce or busier sites.
  • A domain name with access to its DNS settings.
  • An SSH client.

Understanding the stack

Each component has a clear job. Nginx receives web requests, serves static files such as images and stylesheets directly, and passes PHP requests on. PHP-FPM runs WordPress's PHP code in a pool of worker processes. MariaDB, a drop-in MySQL replacement, stores posts, settings, users and orders. Knowing this helps with troubleshooting: a 502 error points to PHP-FPM, a database connection error to MariaDB, and a 404 on every page except the homepage to the Nginx rewrite rules.

On a 2 GB VPS, this stack typically uses a few hundred megabytes at idle, leaving plenty of room for PHP workers and database buffers. As traffic grows, the number of PHP-FPM workers and the MariaDB buffer pool are the two settings most worth tuning.

Step 1: Secure the server

Log in as root, then create a user, set up SSH keys, enable the firewall and update packages:

adduser deploy
usermod -aG sudo deploy
apt update && apt upgrade -y
ufw allow OpenSSH
ufw enable

Our VPS security checklist covers SSH keys, disabling password login and automatic updates.

Step 2: Point your domain to the server

Create an A record for example.com and www pointing to your VPS IPv4 address, and an AAAA record for IPv6 if you use it. Doing this early gives DNS time to propagate before you request SSL. See how to point a domain to your server.

Step 3: Install Nginx, PHP and MariaDB

sudo apt install nginx mariadb-server php-fpm php-mysql php-curl php-gd \
  php-intl php-mbstring php-xml php-zip php-imagick
sudo ufw allow "Nginx Full"

Secure MariaDB:

sudo mariadb-secure-installation

Answer the prompts to remove anonymous users, disallow remote root login and remove the test database.

Step 4: Create the database

sudo mariadb
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 5: Download WordPress

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mkdir -p /var/www/example.com
sudo cp -a wordpress/. /var/www/example.com/
sudo chown -R www-data:www-data /var/www/example.com

Step 6: Configure wp-config.php

cd /var/www/example.com
sudo -u www-data cp wp-config-sample.php wp-config.php
sudo -u www-data nano wp-config.php

Set DB_NAME, DB_USER and DB_PASSWORD. Replace the authentication keys and salts with fresh values from the official WordPress secret-key generator. Add define('DISALLOW_FILE_EDIT', true); to disable the built-in theme and plugin editor.

Step 7: Configure Nginx

Create /etc/nginx/sites-available/example.com (adjust the PHP socket to match your installed version, for example php8.3-fpm.sock):

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php;
    client_max_body_size 64M;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

    location ~ /\.(?!well-known) {
        deny all;
    }

    location ~* \.(css|js|jpg|jpeg|png|gif|webp|svg|ico|woff2)$ {
        expires 30d;
        access_log off;
    }
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Step 8: Add free SSL

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Choose to redirect HTTP to HTTPS. Certbot sets up automatic renewal; test it with sudo certbot renew --dry-run.

Step 9: Run the WordPress installer

Visit https://example.com, choose your language, and create the admin account. Use a unique username (not "admin") and a strong password, and use an email address you check.

Step 10: Tune PHP

Edit /etc/php/8.3/fpm/php.ini and adjust:

  • upload_max_filesize = 64M and post_max_size = 64M
  • memory_limit = 256M
  • OPcache enabled (default on Ubuntu) with opcache.memory_consumption=128

Restart with sudo systemctl restart php8.3-fpm.

Performance: caching

  • Page caching: use a caching plugin, or Nginx FastCGI cache for advanced setups. Exclude logged-in users, carts and checkouts.
  • Object caching: install Redis (sudo apt install redis-server php-redis) and a Redis object cache plugin to speed up database-heavy sites.
  • Images: compress and serve modern formats.
  • Real cron: add define('DISABLE_WP_CRON', true); and a system cron entry to run wp-cron.php every five minutes.

Security hardening

  • Keep WordPress core, themes and plugins updated; remove unused ones.
  • Use two-factor authentication for admin accounts.
  • Rate limit or protect wp-login.php and xmlrpc.php with Nginx rules or fail2ban.
  • Keep file ownership as www-data and avoid 777 permissions.
  • Install only plugins from reputable sources.

Backups

Back up the database (with mysqldump) and the wp-content directory daily, and keep copies off-site. Test restores. Our 3-2-1 backup guide shows a complete approach.

Troubleshooting

ProblemLikely causeFix
502 Bad GatewayWrong PHP-FPM socket path or PHP-FPM stoppedCheck socket in Nginx config; restart php-fpm
Database connection errorWrong credentials in wp-config.phpCheck DB name, user and password
Permalinks return 404Missing try_files ruleUse the location / block above
Upload size errorLimits too lowRaise PHP limits and client_max_body_size
Plugin asks for FTP detailsFile ownership incorrectchown files to www-data

Keeping WordPress updated safely

Updates fix security issues, so delaying them is risky, but an update can occasionally break a theme or plugin. A safe routine is to enable automatic minor core updates, review plugin updates weekly, and take a quick backup before applying them. For important sites, clone the site to a staging subdomain on the same VPS, apply updates there first and check key pages before updating production. WP-CLI makes this faster: wp plugin update --all and wp core update can be scripted after a backup step.

Monitoring your site

Set up an external uptime monitor that checks your homepage for a specific word, so you catch both outages and PHP errors. Watch disk space and memory with simple alerts, and review the Nginx error log and PHP-FPM log after updates. WordPress's built-in Site Health screen also flags outdated PHP versions, missing extensions and failed scheduled events.

Adding more sites

Repeat steps 4 to 8 for each site with its own database, user, directory and Nginx server block. Keep an eye on RAM as you add sites, and resize the VPS when usage regularly exceeds about 75 percent.

Get started

Deploy a Linux VPS with Ubuntu 24.04 in one of ten Standard locations, pay with crypto, and follow these steps to have WordPress running in under an hour.

Frequently asked questions

Do I need a VPS for WordPress?

No. Shared hosting with LiteSpeed handles most WordPress sites with less maintenance. A VPS makes sense for busy sites, custom stacks or several sites with full control.

How much RAM does a WordPress VPS need?

1 GB can run a small site with careful tuning, 2 GB is comfortable for one or two sites, and 4 GB suits WooCommerce or several busy sites.

Which PHP version should I use?

Use a currently supported PHP version that WordPress recommends. Ubuntu 24.04 ships PHP 8.3.

Should I use Nginx or Apache?

Both work well. Nginx with PHP-FPM is efficient and popular on VPS. Apache is simpler if you rely heavily on .htaccess rules.

How do I get a free SSL certificate?

Use Certbot with Let's Encrypt once your domain points to the server. It installs and renews certificates automatically.

#wordpress#install wordpress#wordpress vps#nginx#php-fpm#mariadb#lemp

Plans in this article

Servers mentioned here

VPS Basic

Standard
$2.79 /mo
$5.38Save 48% billed monthly
  • 1 vCPU
  • 2 GB RAM
  • 60 GB NVMe
  • 3 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6
Most popular

VPS Pro

Standard
$4.69 /mo
$10.42Save 55% billed monthly
  • 2 vCPU
  • 4 GB RAM
  • 120 GB NVMe
  • 5 TB traffic
  • Root access · dedicated IPv4
  • Ashburn · London · Amsterdam · Frankfurt +6
Popular

Cloud Grow

Standard
$1.89 /mo
$3.22Save 41% billed monthly
  • Shared CPU
  • 2 GB RAM
  • 25 GB NVMe
  • Unmetered traffic
  • 5 websites · free SSL
  • Ashburn · London · Amsterdam · Frankfurt +6

Keep reading

Related articles

Live Chat · offline