Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

How to host WordPress on a VPS: install it on Ubuntu 24.04 with Nginx, PHP 8.3 and MariaDB

Hosting WordPress on your own VPS gives you root access, your choice of stack and no shared limits, and it gives you the server jobs as well. This guide takes a fresh Ubuntu 24.04 server to a working, HTTPS-secured WordPress site with correct file permissions, page caching and automatic backups, and shows how to check each step before you move on.

Short answer: To host WordPress on a VPS, install Nginx, PHP 8.3-FPM and MariaDB on Ubuntu 24.04, create a database and a limited database user, download and verify WordPress, point an Nginx server block at it, add a Let's Encrypt certificate and run the installer. Then set permissions to 755 for directories, 644 for files and 440 for wp-config.php, turn on Nginx FastCGI caching and schedule database and file backups.

What you need before you start

This guide builds a LEMP stack (Linux, Nginx, MariaDB, PHP-FPM) on a fresh Ubuntu 24.04 VPS and puts one WordPress site on it. You need:

  • An Ubuntu 24.04 VPS and a sudo user. If the server is brand new, do Ubuntu VPS initial setup first: a non-root user, SSH keys and updates.
  • A domain whose A record points at the VPS. Point a domain to a VPS shows the records and how to check them. Remove any AAAA record that does not point at this server, or Let's Encrypt validates over IPv6 and fails.
  • Ports 80 and 443 open in both the server firewall and the provider's network firewall (Step 2).
  • At least 2 GB of RAM for one well-cached site, and 4 GB as a starting point for a production site with the database on the same server. These are our own sizing figures from how much RAM a VPS needs; WordPress.org lists software requirements and no RAM minimum.

The commands use example.com as the domain, /var/www/example.com as the site folder, wordpress as the database name and wpuser as the database user. Replace them with your own.

Why these versions

The WordPress requirements page recommends PHP 8.3 or greater and MariaDB 10.11 or greater (or MySQL 8.4 or greater), with Apache or Nginx as the web server. Ubuntu 24.04 ships packages that meet that list without adding third-party repositories:

Packages on Ubuntu 24.04 (noble) and the WordPress recommendation
ComponentUbuntu 24.04 packageWordPress recommends
PHPphp8.3-fpm 8.3.6PHP 8.3 or greater
Databasemariadb-server 10.11.13MariaDB 10.11 or greater
Web servernginx 1.24.0Apache or Nginx

Ubuntu's mysql-server package on 24.04 is MySQL 8.0, which is below the MySQL 8.4 that WordPress.org lists, so this guide uses MariaDB. Version numbers above are the amd64 builds listed on packages.ubuntu.com on 29 November 2026; security updates raise the last digits.

Step 1: install Nginx, PHP 8.3-FPM and MariaDB

sudo apt update
sudo apt install nginx mariadb-server php8.3-fpm php8.3-mysql php8.3-curl \
  php8.3-gd php8.3-intl php8.3-mbstring php8.3-xml php8.3-zip php-imagick
sudo mariadb-secure-installation

The PHP packages are the extensions that WordPress and its Site Health screen look for. php8.3-fpm depends on php8.3-opcache, so OPcache is installed with it. In mariadb-secure-installation, press Enter at the current-password prompt, answer n to switching authentication and to changing the root password (root already logs in through the Unix socket), then answer y to removing anonymous users, disallowing remote root login and removing the test database. The exact prompts differ a little between versions.

Check that all three services run, and that the web server answers:

systemctl is-active nginx mariadb php8.3-fpm
curl -I http://127.0.0.1

Expect three lines reading active and an HTTP/1.1 200 OK for the default "Welcome to nginx" page.

Step 2: open ports 80 and 443

There are two firewalls to check: ufw on the server and a network firewall in your provider's panel. On the server:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw status verbose

The Nginx Full profile comes with the Nginx package from Step 1. Run sudo ufw enable only after OpenSSH is allowed, or you cut off your own SSH session. Our UFW guide covers the safe order and what to do after a lockout.

Step 3: create the database and a limited user

On Ubuntu, MariaDB's root account logs in through the Unix socket, so use sudo mariadb with no password. If you see "Access denied" instead, see Access denied for user 'root'@'localhost'. Generate a long random password first and keep it for Step 5:

openssl rand -base64 24
sudo mariadb
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'paste-the-random-password-here';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
EXIT;

The user can reach only its own database, and only from the server itself. WordPress never needs the MariaDB root account.

Confirm the new login works before moving on. Type the password at the prompt:

mariadb -u wpuser -p wordpress -e "SELECT 1;"

Step 4: download and verify WordPress

cd /tmp
curl -fLO https://wordpress.org/latest.tar.gz
curl -fLO https://wordpress.org/latest.tar.gz.sha1
echo "$(cat latest.tar.gz.sha1)  latest.tar.gz" | sha1sum -c -

The last command must print latest.tar.gz: OK. If it prints FAILED, delete both files and download again. Then unpack into the site folder:

sudo mkdir -p /var/www/example.com
sudo tar -xzf latest.tar.gz -C /var/www/example.com --strip-components=1
sudo cp /var/www/example.com/wp-config-sample.php /var/www/example.com/wp-config.php

--strip-components=1 drops the top-level wordpress folder so that index.php sits directly in /var/www/example.com.

Step 5: set up wp-config.php

Print a fresh set of authentication keys and salts. They come from WordPress.org's own generator:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

Open the file with sudo nano /var/www/example.com/wp-config.php. Replace the eight placeholder define lines in the "Authentication Unique Keys and Salts" block with the generated lines, and set the database values:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'paste-the-random-password-here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8mb4' );
define( 'DB_COLLATE', '' );

Above the line that reads "That's all, stop editing!", add two hardening constants from the WordPress.org wp-config documentation: one switches off the plugin and theme code editor in the dashboard, the other forces HTTPS for logins and the admin area:

define( 'DISALLOW_FILE_EDIT', true );
define( 'FORCE_SSL_ADMIN', true );

FORCE_SSL_ADMIN needs the certificate from Step 8, so the login page works over HTTPS only after that step.

Step 6: set ownership and permissions

The WordPress hardening guide recommends 755 for directories, 644 for files and 400 or 440 for wp-config.php. On a single-site VPS, the simplest setup that also lets the dashboard install updates is to make the Nginx and PHP-FPM user, www-data, the owner:

sudo chown -R www-data:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;
sudo chmod 440 /var/www/example.com/wp-config.php

When the file owner is the PHP user, WordPress can write plugin, theme and core updates itself and does not ask for FTP details. The trade-off is that a PHP flaw in one plugin can then rewrite your code. The hardening guide describes a stricter model: your own user owns the files, only wp-content is writable by the web server, and you update from the command line. It is worth it on a server that holds several sites; this guide keeps the simple model and compensates with the Nginx rules in Step 7 and with backups in Step 11.

To edit wp-config.php later, use sudo nano; root can write a 440 file. Do not run chmod 777 on anything.

Step 7: configure the Nginx server block

Create /etc/nginx/sites-available/example.com with sudo nano:

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;

    # no PHP from the uploads folder, no dotfiles (except .well-known)
    location ~* /(?:uploads|files)/.*\.php$ { deny all; }
    location ~ /\.(?!well-known) { deny all; }

    # pretty permalinks: real file or folder first, otherwise WordPress
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

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

    # long browser cache for static files
    location ~* \.(?:css|js|jpg|jpeg|png|gif|webp|svg|ico|woff2)$ {
        expires 30d;
        access_log off;
    }
}

Order matters here. Nginx uses the first matching regular-expression location, so the two deny lines must sit above the \.php$ block, or a PHP file uploaded to wp-content/uploads would still run. The upload and permalink rules follow the WordPress.org Nginx page. WordPress cannot write rewrite rules for Nginx, so there is no .htaccess to rely on.

Enable the site, remove the default one, test and reload:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

nginx -t must print syntax is ok and test is successful. Then check that the domain reaches this server:

curl -I http://example.com/

Before the installer runs, a new WordPress answers with a 302 redirect to /wp-admin/install.php. That redirect confirms that Nginx, PHP-FPM and the database settings all work together. Raise PHP's upload limits to match Nginx's 64 MB, because PHP's own limits are separate:

sudo tee /etc/php/8.3/fpm/conf.d/99-wordpress.ini >/dev/null <<'EOF'
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
EOF
sudo systemctl restart php8.3-fpm

Step 8: add a Let's Encrypt certificate

Install the certificate before you run the WordPress installer, so the site address is stored as https:// from the start. Certbot's own instructions use the snap package:

sudo apt remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot renew --dry-run

Certbot adds the listen 443 ssl block and the HTTP to HTTPS redirect for you. The --dry-run line proves that automatic renewal works. If a step fails, our Let's Encrypt on Nginx with Certbot guide has a diagnosis table for each Certbot error.

Step 9: run the WordPress installer

Open https://example.com/wp-admin/install.php, choose a language, then enter a site title, an admin user name that is not admin, a strong password and your email address. You land on the login page when it finishes.

If you prefer the command line, WP-CLI does the same in one command. Install it, then run it as www-data so file ownership stays correct:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
cd /var/www/example.com
sudo -u www-data wp core install --url=https://example.com --title="My Site" \
  --admin_user=siteowner --admin_email=you@example.com --prompt=admin_password

Afterwards set permalinks to Post name in Settings, Permalinks, and confirm that Tools, Site Health shows no critical issues. Our guide to installing WordPress on cPanel or an Ubuntu VPS lists more first settings.

Step 10: add basic caching

Three layers cut the work that PHP and MariaDB do for each visit. None needs a plugin.

OPcache (PHP code cache)

OPcache keeps compiled PHP in memory. It comes with php8.3-fpm, and the PHP manual lists opcache.enable as on by default with 128 MB of shared memory. Confirm the module is loaded:

php -m | grep -i opcache

The output is Zend OPcache.

Browser caching

The expires 30d block in Step 7 tells browsers to keep images, CSS and JavaScript for 30 days. WordPress adds a version query string to its own CSS and JavaScript, so updates still reach visitors.

Nginx FastCGI page cache

The page cache stores finished HTML for visitors who are not logged in, so PHP and MariaDB are skipped on a cache hit. Create the cache folder and a file that defines the cache zone. Files in /etc/nginx/conf.d/ are loaded inside the http block:

sudo mkdir -p /var/cache/nginx/wordpress
sudo chown www-data:www-data /var/cache/nginx/wordpress
echo 'fastcgi_cache_path /var/cache/nginx/wordpress levels=1:2 keys_zone=WPCACHE:50m max_size=512m inactive=60m;' \
  | sudo tee /etc/nginx/conf.d/wp-cache.conf

In the server block, add the skip rules just below client_max_body_size. They keep logged-in users, commenters, form posts, search results and the admin area out of the cache:

    set $skip_cache 0;
    if ($request_method = POST) { set $skip_cache 1; }
    if ($query_string != "") { set $skip_cache 1; }
    if ($request_uri ~* "/wp-admin/|/wp-login\.php|/wp-json/|/xmlrpc\.php") { set $skip_cache 1; }
    if ($http_cookie ~* "comment_author|wordpress_logged_in|wp-postpass|woocommerce_items_in_cart|wp_woocommerce_session") { set $skip_cache 1; }

Then add these lines inside the location ~ \.php$ block, under fastcgi_pass:

        fastcgi_cache WPCACHE;
        fastcgi_cache_key "$scheme$request_method$host$request_uri";
        fastcgi_cache_valid 200 301 302 10m;
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;
        add_header X-Cache $upstream_cache_status;

Test, reload and request the home page twice. The first request fills the cache, the second reads it:

sudo nginx -t && sudo systemctl reload nginx
curl -sI https://example.com/ | grep -i x-cache
curl -sI https://example.com/ | grep -i x-cache

The first line reads X-Cache: MISS and the second X-Cache: HIT. If the second is still MISS or BYPASS, a rule above is skipping the page or a plugin sends a Set-Cookie or Cache-Control: no-cache header, and Nginx respects both. A cached page can be up to 10 minutes old after you edit it. Clear the cache with:

sudo find /var/cache/nginx/wordpress -type f -delete

Keep the cache off checkout and account pages. The cookie list above covers WooCommerce carts; add /cart/, /checkout/ and /my-account/ to the URL rule on a shop. For more speed work, see WordPress speed optimization for India.

Step 11: back up the database and the files

The WordPress.org backup guide says a full backup has two parts, the database and the files, and that you need both to restore a typical site. Put both in one script. mariadb-dump is MariaDB's dump tool, and --single-transaction reads InnoDB tables from one consistent snapshot without locking them. Create /usr/local/sbin/wp-backup.sh with sudo nano:

#!/bin/bash
set -euo pipefail
umask 077
SITE=/var/www/example.com
DEST=/var/backups/wordpress
STAMP=$(date +%F-%H%M)
mkdir -p "$DEST"
mariadb-dump --single-transaction wordpress | gzip > "$DEST/db-$STAMP.sql.gz"
tar -czf "$DEST/files-$STAMP.tar.gz" -C "$SITE" .
find "$DEST" -type f -mtime +7 -delete

The script runs as root, so the dump uses the Unix socket and needs no password in the file. umask 077 makes the archives readable only by root, which matters because wp-config.php holds the database password. The last line removes archives older than 7 days. Make it executable, run it once and schedule it:

sudo chmod 700 /usr/local/sbin/wp-backup.sh
sudo /usr/local/sbin/wp-backup.sh
ls -lh /var/backups/wordpress
echo '30 2 * * * root /usr/local/sbin/wp-backup.sh' | sudo tee /etc/cron.d/wp-backup

A backup that sits on the same disk disappears with the server, so copy it elsewhere. From another machine you control, rsync -az user@your-server:/var/backups/wordpress/ ./wp-backups/ pulls the archives over SSH (the account needs read access to that folder). To restore, unpack the files first, then import the database, as the WordPress.org guide orders it:

sudo tar -xzf files-STAMP.tar.gz -C /var/www/example.com
gunzip -c db-STAMP.sql.gz | sudo mariadb wordpress

Replace STAMP with the date and time in the file name. Try a restore on a spare server before you need it. WordPress.org also advises taking a manual backup before any upgrade.

Keep it updated

  • WordPress core: new installs update to minor and major core releases automatically by default (WordPress 5.6 and later), and the owner setup in Step 6 lets WordPress write those updates. Plugin and theme updates can be switched on for each item in the dashboard or run with sudo -u www-data wp plugin update --all.
  • Ubuntu, Nginx, PHP and MariaDB: run sudo apt update && sudo apt upgrade on a schedule you keep, and reboot when a kernel update asks for it.
  • Before every update: run sudo /usr/local/sbin/wp-backup.sh.

Apache instead of Nginx

The WordPress.org requirements page recommends Apache and Nginx alike, so either is a valid choice. Install apache2 in place of nginx, enable PHP-FPM, and let WordPress write its permalink rules to .htaccess:

sudo apt install apache2 mariadb-server php8.3-fpm php8.3-mysql php8.3-curl \
  php8.3-gd php8.3-intl php8.3-mbstring php8.3-xml php8.3-zip php-imagick
sudo a2enmod proxy_fcgi setenvif rewrite
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2

Create a virtual host in /etc/apache2/sites-available/example.com.conf with ServerName example.com, DocumentRoot /var/www/example.com and a <Directory> block that sets AllowOverride All and Require all granted. Enable it with sudo a2ensite example.com, then use sudo certbot --apache for HTTPS. The database, download, wp-config, permission and backup steps are the same. The FastCGI cache in Step 10 is Nginx-only. For background on the two servers, see What is Nginx.

Troubleshooting: symptom, cause and fix

Common problems after installing WordPress on a VPS
What you seeLikely causeCheck and fix
"Welcome to nginx" pageThe default site is still enabled, or server_name does not match the domainRemove /etc/nginx/sites-enabled/default, fix server_name, then sudo nginx -t and reload
Browser downloads index.php or shows PHP codeThe location ~ \.php$ block is missing or not matchedCompare with Step 7, then sudo nginx -t and reload
502 Bad GatewayPHP-FPM is stopped, or fastcgi_pass names a socket that does not existsystemctl status php8.3-fpm, ls /run/php/, and read /var/log/nginx/error.log
Error establishing a database connectionWrong credentials in wp-config.php, or MariaDB is stoppedsystemctl status mariadb and mariadb -u wpuser -p wordpress -e "SELECT 1;"
Home page loads, every other page gives 404The try_files line in location / is missingRestore try_files $uri $uri/ /index.php?$args; and reload
"413 Request Entity Too Large" on uploadNginx's client_max_body_size is too smallRaise it in the server block; see 413 Request Entity Too Large
Upload fails with a size error from WordPressPHP's upload_max_filesize or post_max_size is too smallSet both in 99-wordpress.ini and restart php8.3-fpm
Dashboard asks for FTP details to updateFiles are not owned by the PHP userRepeat the chown and chmod lines in Step 6
13: Permission denied in the Nginx error logNginx cannot read a file or enter a parent folderDirectories need 755 and files 644 under /var/www/example.com; check namei -l /var/www/example.com/index.php
Redirect loop or mixed-content warningsWordPress Address or Site Address still starts with http://Settings, General; or sudo -u www-data wp option update home https://example.com and the same for siteurl
White screen with no errorA PHP fatal error in a plugin or themeSet WP_DEBUG and WP_DEBUG_LOG to true and read wp-content/debug.log; see WordPress white screen of death
Certbot cannot validate the domainDNS or port 80 is wrongFollow the checks in the Certbot guide

Two logs hold the details: /var/log/nginx/error.log for the web server and /var/log/php8.3-fpm.log for PHP-FPM. If WordPress reports that it ran out of memory, our guide to WordPress memory exhausted shows where to raise the limit.

VPS or WordPress hosting: which fits you

A VPS gives you control and also gives you the jobs. You patch the operating system, watch the logs, set up backups and fix a 502 at an inconvenient hour. That is a fair trade when you want root access, several sites on one server, a custom stack, or other software such as Node.js or Docker beside WordPress. A Bigdomainhost KVM VPS suits that case, with Linux images, root access and Mumbai or Delhi NCR locations.

Bigdomainhost WordPress hosting suits the other case: one or a few sites and no wish to manage a server. It is managed WordPress on LiteSpeed with WordPress pre-installed, a free SSL certificate, 30 days of free backups and free migration from your current host, so the steps in this guide are already done. Our comparison of VPS and shared hosting sets out the trade in more detail. If you want a VPS that someone else looks after, read managed vs unmanaged VPS.

Common mistakes

  • Using the MariaDB root account in wp-config.php. One leaked file then exposes every database. Use the limited wpuser.
  • Putting the deny rules for uploaded PHP below the PHP location. Nginx picks the first matching regular expression, so the rule never applies.
  • Setting chmod -R 777 to fix a permission error. It lets any process on the server write to your site. Fix the owner and use 755 and 644.
  • Enabling ufw without allowing SSH first. Run sudo ufw allow OpenSSH before sudo ufw enable.
  • Leaving an AAAA record that points elsewhere. Let's Encrypt tries IPv6 first and the check fails.
  • Keeping backups only on the same disk. Copy them to another machine and test a restore.
  • Caching the admin area or the checkout. Keep the skip rules from Step 10 and test while logged in.
  • Skipping the hash check on the download. The sha1sum line confirms the file is intact before you unpack it.

This guide was written by the Bigdomainhost team with AI assistance. Commands and behaviour were checked against the WordPress.org developer documentation, the nginx.org and PHP manuals, Certbot's instructions and Ubuntu package listings on 29 November 2026; package versions are those listed for Ubuntu 24.04 on that date.

Sources (checked )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

Can I run WordPress on a VPS without a control panel?

Yes. A LEMP stack of Nginx, PHP-FPM and MariaDB needs no control panel, and WordPress.org lists Apache and Nginx as recommended web servers. You manage the server over SSH, which costs nothing extra and uses less memory than a panel, but you handle updates and backups yourself.

Should I use Nginx or Apache for WordPress on Ubuntu 24.04?

Either works. The WordPress.org requirements page recommends both. Nginx needs its rewrite rules in the server block because it ignores .htaccess, while Apache lets WordPress write permalink rules to .htaccess. Pick the one you know; this guide uses Nginx and shows the Apache differences.

Is MariaDB or MySQL better for WordPress on Ubuntu 24.04?

MariaDB 10.11 is the better fit on 24.04. WordPress.org recommends MariaDB 10.11 or greater or MySQL 8.4 or greater, and Ubuntu 24.04's mysql-server package is MySQL 8.0, which is below that line. The mariadb-server package is 10.11, which meets it.

What owner and file permissions should WordPress use on an Ubuntu VPS?

Use 755 for directories, 644 for files and 440 for wp-config.php, as the WordPress hardening guide recommends. Making www-data the owner lets the dashboard install updates. A stricter setup has your own user own the files and leaves only wp-content writable by the web server.

Why do only my WordPress home page load and every other page give a 404 on Nginx?

The location / block is missing the try_files $uri $uri/ /index.php?$args; line. Nginx then looks for a real file for each permalink and returns 404 when it finds none. Add the line, run sudo nginx -t, reload Nginx and save the permalinks again.

How do I back up a WordPress site on my own VPS?

Back up the database and the files together. Dump the database with mariadb-dump --single-transaction, archive the site folder with tar, run both from a cron job, delete old archives and copy them to another machine. Test a restore on a spare server before you rely on it.

Do I need to point my domain at the VPS before installing WordPress?

Yes for the HTTPS step. Let's Encrypt can only issue a certificate when the domain's A record resolves to the server and port 80 is reachable. You can build the stack first, but run Certbot before the WordPress installer so the site address is saved as https.

When is WordPress hosting a better choice than a VPS?

Choose WordPress hosting when you run one or a few sites and do not want to patch an operating system or fix server errors. It comes with WordPress pre-installed and a free SSL certificate. Choose a VPS when you need root access, several sites or other software beside WordPress.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.