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
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.
Type your own values and the commands on this page follow
Before you start, point your domain's A record at the server and work through the security checklist.
1. Install the packages#
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 -vphp -v should report PHP 8.3.
2. Create the database#
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';
EOF3. Download
WordPress#
The sha1sum -c line should print latest.tar.gz: OK before you unpack anything.
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_DOMAIN4. Configure
Nginx#
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.
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/tcpnginx -t should end with test is successful.
5. Add SSL before you type any password#
sudo snap install --classic certbot
sudo ln -sf /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d YOUR_DOMAIN --redirectDetails 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: setupload_max_filesizeandpost_max_sizeto 64M, then runsudo 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.
sudo mariadb-dump --single-transaction wordpress | gzip > ~/wordpress-$(date +%F).sql.gzCommon problems#
| Symptom | Fix |
|---|---|
| 502 Bad Gateway | Check the socket name with ls /run/php and make |
| 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.