Initech
KB-19 Печать

Run WordPress on a VPS: Full Setup Guide

Quick answer: install nginx, MariaDB and PHP on an Ubuntu VPS, create a database, drop the WordPress files into your web root, point a server block at them, add HTTPS with certbot, and finish the installer in your browser. The whole process takes about 30 minutes. If you would rather skip every step below, our Amazon Lightsail line offers a WordPress blueprint that arrives preinstalled.

What you need

  • A VPS running Ubuntu 24.04 (1GB of RAM is enough to start)
  • A domain with an A record pointed at your server IP
  • SSH access as root or a sudo user

Step 1: Install the stack

sudo apt update
sudo apt install nginx mariadb-server php-fpm php-mysql \
  php-curl php-gd php-xml php-mbstring php-zip php-intl

Ubuntu 24.04 ships PHP 8.3, which current WordPress fully supports. Run sudo mysql_secure_installation once MariaDB is in, and answer yes to the prompts that remove test data and anonymous users.

Step 2: Create the database

sudo mysql
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;

Step 3: Download WordPress

cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mv wordpress /var/www/example.com
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 {} \;

Replace example.com with your domain everywhere it appears in this guide.

Step 4: The nginx server block

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;

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

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

    location ~* \.(jpg|jpeg|png|gif|css|js|ico|webp|svg)$ {
        expires 30d;
    }
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Step 5: HTTPS with certbot

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Certbot edits the server block for you and sets up automatic renewal. Verify with sudo certbot renew --dry-run.

Step 6: wp-config and the installer

cd /var/www/example.com
sudo -u www-data cp wp-config-sample.php wp-config.php
sudo -u www-data nano wp-config.php

Fill in the database name, user and password from step 2. Then replace the block of AUTH_KEY and salt definitions with fresh random values: generate them with the official WordPress secret-key service or with openssl rand -base64 48 per key. Never keep the sample placeholders. Now open https://example.com in a browser and run the five-minute installer: site title, admin user, strong password.

Hardening basics

  • Update relentlessly. Most compromised WordPress sites run outdated plugins. Enable automatic minor core updates and check plugins weekly.
  • Fewer plugins, better plugins. Every plugin is attack surface. Delete anything deactivated.
  • Restrict xmlrpc.php. If you do not use the mobile app or Jetpack, block it in nginx: location = /xmlrpc.php { deny all; }. It is a common brute-force target.
  • Back up on your own schedule. On a VPS, backups are your job, not the host's. Database dumps plus the wp-content directory cover most restores; see our guide on backups and snapshots per provider line for what your platform offers and how to keep an offsite copy.

When a VPS beats shared hosting, and when it does not

A VPS gives you full control: your own PHP settings, real cron, room to tune nginx and add caching, and no noisy neighbors on the same account. Costs stay flat as traffic grows, and nobody suspends you for a traffic spike.

The honest tradeoff: you are the sysadmin. Updates, backups, firewall rules and disk space are yours to manage. If you never want to touch a terminal after setup, managed WordPress hosting or the preinstalled Lightsail blueprint mentioned above will fit better than a hand-built server. If you are comfortable with the steps on this page, a VPS is usually the cheapest fast way to run WordPress.

Make it fast

A stock install on a small VPS is already quick, but three cheap wins matter as traffic grows. First, install a page caching plugin so WordPress serves static HTML to anonymous visitors instead of running PHP for every hit. Second, PHP OPcache is enabled by default on Ubuntu's php-fpm packages; leave it on, it is the single biggest PHP performance feature. Third, the browser-caching location block in the nginx config above keeps repeat visitors from re-downloading images and CSS. If you later outgrow one server, move the database to its own VPS before reaching for anything more exotic.

Quick troubleshooting

  • 502 Bad Gateway: nginx cannot reach PHP. Confirm the socket path in the server block matches the installed PHP version: ls /run/php/.
  • White screen: check /var/log/php8.3-fpm.log and enable WP_DEBUG temporarily in wp-config.php.
  • Permalinks return 404: the try_files line in the server block is missing or the block edits never got reloaded; rerun sudo nginx -t && sudo systemctl reload nginx.
  • Uploads fail: raise upload_max_filesize and post_max_size in /etc/php/8.3/fpm/php.ini, then restart php-fpm.
Помог ли вам данный ответ?
Связанные статьи