Running WordPress on your own VPS gives you dedicated resources and full control over the web server, PHP and database — and makes you responsible for all of them. This guide builds a production-ready WordPress server from scratch on Ubuntu 24.04 LTS with Nginx, PHP-FPM 8.3, MariaDB and a free Let's Encrypt certificate. We also show the Apache variant, the hardening steps to do straight afterwards, and how to fix the errors people hit most often.
When a VPS makes sense for WordPress
Shared or managed WordPress hosting takes care of the server for you. A VPS is the better fit when:
- the site has outgrown shared resources (traffic peaks, large shops, heavy plugins),
- you need server-level tools such as Redis, custom Nginx rules or background workers,
- you want to run several sites with full control of PHP versions and limits.
The price of that control is maintenance: updates, backups, security and monitoring are now your job. If that sounds unappealing, managed WordPress hosting is probably the better choice.
Before you commit, it helps to be honest about the weekly time it takes: checking updates, reading logs now and then, testing restores and renewing anything that doesn't renew itself. For one person running one site that is perhaps half an hour a week — but it never drops to zero, and when something breaks at night, there is no one else to call.
Before you start
You need:
- A VPS with Ubuntu 24.04 and at least 1–2 GB of RAM.
- SSH access as a user with
sudo— see how to connect to a Linux VPS with SSH. - A domain whose A record (and AAAA for IPv6) points to the VPS. See pointing your domain to your server.
Start with an up-to-date system:
sudo apt update && sudo apt upgrade -y
Step 1: install Nginx, PHP-FPM and MariaDB
Ubuntu 24.04 ships PHP 8.3, MariaDB 10.11 and a current Nginx in its own repositories:
sudo apt install -y 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 php8.3-bcmath php-imagick
Secure MariaDB — remove anonymous users and the test database, and keep root login over the local socket:
sudo mariadb-secure-installation
Check that all three services are running:
systemctl status nginx php8.3-fpm mariadb --no-pager
Step 2: create the database
Open the MariaDB shell with sudo mariadb and create a dedicated database and user:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'A_LONG_RANDOM_PASSWORD';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Never let WordPress connect as the MariaDB root user.
Step 3: download and configure WordPress
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mkdir -p /var/www/example.com
sudo cp -a /tmp/wordpress/. /var/www/example.com/
cd /var/www/example.com
sudo cp wp-config-sample.php wp-config.php
Edit wp-config.php with sudo nano wp-config.php and fill in DB_NAME, DB_USER and DB_PASSWORD. Then replace the placeholder keys with fresh ones — fetch them with the command below and paste the output over the eight define() lines:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
Set ownership and permissions so PHP-FPM (running as www-data) can write uploads and updates, but nothing is world-writable:
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 640 /var/www/example.com/wp-config.php
Warning: Never use
chmod 777to "fix" an upload error. It lets any process on the server change your files. Fix the owner instead.
Step 4: configure Nginx
Create /etc/nginx/sites-available/example.com:
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;
}
# Never execute PHP from the uploads folder
location ~* ^/wp-content/uploads/.*\.php$ {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.(?!well-known) {
deny all;
}
}
The uploads rule must come before the general PHP block, because Nginx uses the first matching regex location. Enable the site, remove the default 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
New to Nginx? Our guide on installing Nginx on Ubuntu explains server blocks in more depth.
Before you go live, check the setup from the server itself. A 200 or 302 from WordPress means Nginx, PHP-FPM and the database are talking to each other:
curl -sI -H 'Host: example.com' http://127.0.0.1 | head -n 1
sudo tail -n 20 /var/log/nginx/error.log
An empty error log at this point is exactly what you want. A 502 means Nginx can't reach PHP-FPM; jump to the troubleshooting section below.
Prefer Apache?
Apache works just as well with PHP-FPM. Install apache2 instead of nginx, then enable the FastCGI proxy and rewrites:
sudo apt install -y apache2
sudo a2enmod proxy_fcgi setenvif rewrite
sudo a2enconf php8.3-fpm
sudo systemctl reload apache2
Create a virtual host with DocumentRoot /var/www/example.com and AllowOverride All for that directory so WordPress's .htaccess permalink rules work. Use 'Apache Full' in the firewall and certbot --apache in the next steps.
Step 5: firewall and HTTPS
Allow SSH and web traffic, then enable UFW — in that order, so you don't lock yourself out:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
Install certbot and request a certificate. The Nginx plugin edits your server block and adds the HTTP-to-HTTPS redirect:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot renew --dry-run
Renewal runs automatically through a systemd timer; the dry run proves it will work. See configuring a firewall on your Linux VPS for more UFW rules.
Step 6: finish the installation
Open https://example.com and complete the WordPress wizard: site title, admin user (not admin), a strong password and your email. Then set permalinks to Post name under Settings → Permalinks.
Optional: install WP-CLI
WP-CLI lets you update, back up and troubleshoot WordPress from the terminal, which is far quicker than clicking through the dashboard on a server you already manage over SSH:
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
Run it as the user that owns the files, so you don't create root-owned files PHP can't touch:
cd /var/www/example.com
sudo -u www-data wp core version
sudo -u www-data wp plugin update --all
Hardening and maintenance
- Updates: patch the OS weekly (
sudo apt update && sudo apt upgrade), and keep WordPress, themes and plugins current. Consider enablingunattended-upgradesfor security fixes. - SSH: key-based login only, no root password login. Our checklist on securing your VPS covers the rest.
- Backups: combine server snapshots with your own nightly database dump and
wp-contentarchive copied off the server — see backing up WordPress. - Performance: OPcache is on by default in PHP-FPM. Add a page cache that works with Nginx and, for busy sites, Redis (
sudo apt install redis-server php8.3-redis) as an object cache. - Monitoring: watch RAM and swap. If PHP-FPM workers are being killed, lower
pm.max_childrenin/etc/php/8.3/fpm/pool.d/www.confor add RAM.
Common errors and fixes
- 502 Bad Gateway. PHP-FPM isn't running, or the socket path in Nginx is wrong. Check
systemctl status php8.3-fpmand confirm/run/php/php8.3-fpm.sockexists. - "Error establishing a database connection." Wrong credentials in
wp-config.php, or MariaDB is down:systemctl status mariadb. - White screen. A fatal PHP error. Read
/var/log/nginx/error.log, or temporarily setWP_DEBUGandWP_DEBUG_LOGtotrueand checkwp-content/debug.log. - "413 Request Entity Too Large" or upload limit errors. Raise
client_max_body_sizein Nginx andupload_max_filesizeandpost_max_sizein/etc/php/8.3/fpm/php.ini, then reload Nginx and restartphp8.3-fpm. - WordPress asks for FTP details when updating. The files aren't owned by
www-data. Re-run thechowncommand from step 3.
In short
Install Nginx, PHP 8.3-FPM and MariaDB from Ubuntu's repositories, create a dedicated database user, unpack WordPress into /var/www, give it to www-data, block PHP in uploads, open the firewall and let certbot handle HTTPS. Then keep it updated, backed up and monitored.
WordPress on a Hostigan VPS
A Hostigan VPS gives you KVM virtualisation, full root access, NVMe storage and IPv4 + IPv6, with Ubuntu among the ready-made images — everything this guide assumes. Snapshots on VPS Plus and up give you a rollback point before big changes. If you'd rather not manage the server yourself, our WordPress hosting handles core updates for you.
Frequently asked questions
A single small to medium site runs comfortably on 2 GB of RAM with Nginx, PHP-FPM and MariaDB. Webshops, several sites or heavy plugins are happier with 4 GB or more.