Intermediate

Install WordPress on an Ubuntu VPS with Nginx, step by step

Nginx, PHP-FPM, MariaDB and a free SSL certificate, with safe file permissions

On this page
  1. 1. Install the packages
  2. 2. Create the database
  3. 3. Download WordPress
  4. 4. Configure Nginx
  5. 5. Add SSL before you type any password
  6. 6. Finish setup in the browser
  7. Get it ready for real use
  8. Common problems
  9. Frequently asked questions

Everything WordPress needs on a VPS (Nginx, PHP-FPM and MariaDB) installs straight from apt. This guide uses Ubuntu 24.04 LTS, which ships PHP 8.3. Plan on 2 GB of RAM or more.

See server specs and prices on Cloud Server pricing, or read Build a business website with WordPress yourself for a beginner-friendly route.

Before you start, point your domain's A record at the server and work through the security checklist.

1. Install the packages#

Terminal
sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zip php-imagick unzip
php -v

php -v should report PHP 8.3.

2. Create the database#

Terminal
sudo mariadb <<'EOF'
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'DB_PASSWORD';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
EOF

3. Download WordPress#

The sha1sum -c line should print latest.tar.gz: OK before you unpack anything.

Terminal
cd /tmp
curl -fsSLO https://wordpress.org/latest.tar.gz
curl -fsSL https://wordpress.org/latest.tar.gz.sha1 -o wp.sha1
echo "$(cat wp.sha1)  latest.tar.gz" | sha1sum -c
sudo mkdir -p /var/www/YOUR_DOMAIN
sudo tar -xzf latest.tar.gz --strip-components=1 -C /var/www/YOUR_DOMAIN
sudo chown -R www-data:www-data /var/www/YOUR_DOMAIN

4. Configure Nginx#

/etc/nginx/sites-available/YOUR_DOMAIN
server {
    listen 80;
    listen [::]:80;
    server_name YOUR_DOMAIN;
    root /var/www/YOUR_DOMAIN;
    index index.php;
    client_max_body_size 64m;

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

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        # The version must match the socket in /run/php
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

}

The uploads block must sit above the \.php$ block, because Nginx uses the first regex that matches. It stops PHP files in the uploads folder from running.

Terminal
sudo ln -s /etc/nginx/sites-available/YOUR_DOMAIN /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo ufw allow 80,443/tcp

nginx -t should end with test is successful.

5. Add SSL before you type any password#

Terminal
sudo snap install --classic certbot
sudo ln -sf /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d YOUR_DOMAIN --redirect

Details and fixes are in Free SSL with Let's Encrypt on Nginx.

6. Finish setup in the browser#

Open https://YOUR_DOMAIN, pick your language, then enter database wordpress, user wordpress, the password you set, and host localhost. Do not name the administrator account admin.

Get it ready for real use#

  • Raise the upload limit in /etc/php/8.3/fpm/php.ini: set upload_max_filesize and post_max_size to 64M, then run sudo systemctl restart php8.3-fpm.
  • Turn on WordPress automatic updates and delete plugins you do not use.
  • Back up both the files and the database.
Terminal
sudo mariadb-dump --single-transaction wordpress | gzip > ~/wordpress-$(date +%F).sql.gz

Common problems#

Symptom Fix
502 Bad Gateway Check the socket name with ls /run/php and make Nginx match it
Error establishing a database connection Check the password in wp-config.php and run systemctl status mariadb
413 Request Entity Too Large Raise client_max_body_size
Permalinks return 404 Check the try_files line

Frequently asked questions#

How much RAM does a WordPress VPS need?

Start at 2 GB for a single site. A WooCommerce shop or a site with many plugins should start at 4 GB.

Is Nginx or Apache better?

Both work. Nginx ignores .htaccess files, so rules go in its configuration file. If your plugins rely heavily on .htaccess, Apache is easier.

Can I run several sites on one VPS?

Yes. Give each domain its own folder, database, database user and Nginx configuration file.

Prefer WordPress installed and ready to use instead of setting it up yourself? See WordPress hosting servers in Thailand.

PlanNVMe diskBandwidthPer hourPer month
1 vCPU · 2 GB32 GB2 TB฿0.38/hr฿229/mo
2 vCPU · 2 GB40 GB4 TB฿0.47/hr฿279/mo
2 vCPU · 4 GB40 GB4 TB฿0.70/hr฿419/mo

Prices when this page was built

Follow the guide on your own server

Create a Cloud Server with Ubuntu, Debian or Windows Server, billed by the hour in Thai baht. Support answers 24/7 in Thai and English.