Deploying WordPress on a VPS: A Complete Guide
Everything from creating the database and user to deploying the files, configuring Nginx, running the installer, and tuning permalinks and caching.
WordPress powers a huge share of the web. This guide assumes your server already has an LNMP stack in place (Linux + Nginx + MySQL/MariaDB + PHP-FPM), with commands geared toward Ubuntu/Debian. If you haven't set up LNMP yet, start with the corresponding article in this knowledge base.
1. Create the database and user
WordPress should have its own database and a dedicated account—never run it as root. Open a database shell:
sudo mysql -u root -p
Then run the following SQL (swap in your own strong password):
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Stick with utf8mb4—it stores emoji and multi-byte characters correctly.
2. Download and extract 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 -r wordpress/* /var/www/example.com/
Set the right ownership and permissions—Nginx and PHP-FPM run as www-data by default:
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 {} \;
3. Configure the Nginx site
Create /etc/nginx/sites-available/example.com:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
That tryfiles ... /index.php?$args; line is the rewrite that makes pretty permalinks work—WordPress needs no .htaccess on Nginx. Match php8.2 to your actual version (run ls /run/php/ to find the socket name). Enable the site and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
4. Run the install wizard
Visit http://your-domain-or-ip in a browser and follow the prompts: database name wordpress, user wpuser, the password you set, and host localhost. The wizard writes wp-config.php and asks for a site title and admin account. Once it finishes, log in at /wp-admin.
After that, go to Settings → Permalinks, pick a friendly structure like "Post name," and save. Combined with the rewrite above, you'll get clean URLs.
5. Basic performance tuning
- PHP OPcache: edit /etc/php/8.2/fpm/php.ini to enable bytecode caching:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
- PHP-FPM process pool: on low-memory boxes, set pm to ondemand in /etc/php/8.2/fpm/pool.d/www.conf so idle workers don't eat RAM; for high traffic, use dynamic and raise pm.maxchildren. Apply changes with sudo systemctl restart php8.2-fpm.
- Caching plugin: install WP Super Cache or W3 Total Cache from the dashboard to serve static page caches. If you have Redis, add the Redis Object Cache plugin to cache database queries too.
- Finally, grab a free HTTPS certificate with Certbot and move the site to port 443.
Summary
The path to a working WordPress site is straightforward: create the database and user, deploy the files with correct permissions, configure the Nginx site (including the permalink rewrite), run the installer, then turn on OPcache, tune PHP-FPM, and add a caching plugin. Follow these steps and you'll have a clean, fast, and maintainable WordPress site running on your own VPS.