Guideschevron_rightServers

Servers · 10 min read · Updated

How to Install WordPress on a VPS with Nginx

To install WordPress on a VPS, install Nginx, PHP 8.3 with PHP-FPM and MariaDB from Ubuntu 24.04's own packages, create a database and user, unpack the latest WordPress into a site folder, point an Nginx server block at it, turn on HTTPS with Let's Encrypt and finish the five-minute installer in the browser. Then set up an SMTP plugin for email, automatic updates and off-server backups. A typical site runs comfortably on our smallest VPS (6 GB, $37.50 a month).

1. Prepare the Server

Order a VPS with Ubuntu 24.04 and secure it. At your DNS provider, add an A record for example.com (and www) with the server's IP address, so the certificate step works later.

2. Install Nginx, PHP and MariaDB

sudo apt update
sudo apt install -y nginx mariadb-server \
  php8.3-fpm php8.3-mysql php8.3-curl php8.3-xml php8.3-mbstring \
  php8.3-zip php8.3-gd php8.3-intl
sudo ufw allow 'Nginx Full'
sudo mysql_secure_installation      # answer yes to the security questions

3. Create the Database

sudo mariadb <<'SQL'
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
SQL

Use a long random password of your own and keep it for the next step.

4. Download WordPress

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress /var/www/example.com
sudo cp /var/www/example.com/wp-config-sample.php /var/www/example.com/wp-config.php
sudo chown -R www-data:www-data /var/www/example.com

In /var/www/example.com/wp-config.php, set DB_NAME, DB_USER and DB_PASSWORD to the values from step 3, and leave DB_HOST as localhost. Replace the block of put your unique phrase here lines under "Authentication unique keys and salts" with fresh ones from WordPress's generator:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

5. Add the Nginx Site

In /etc/nginx/sites-available/example.com:

server {
    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;
    }

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

    location ~ /\.(?!well-known) {
        deny all;
    }
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

The try_files line gives WordPress its pretty permalinks. For uploads above PHP's default limit, also raise upload_max_filesize and post_max_size in /etc/php/8.3/fpm/php.ini and restart php8.3-fpm.

6. Turn On HTTPS and Run the Installer

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

Certbot adds the certificate to the server block and renews it on a timer. If validation fails, see fixing Certbot validation errors. Then open https://example.com, pick a language, enter the site title and an administrator account (not named "admin"), and sign in.

7. Email, Updates and Backups

  • Email: outgoing port 25 is blocked on every VPS, so password resets and contact forms need an SMTP plugin set to your mail provider on port 587 or 465. See sending email from your server.
  • Updates: keep WordPress, plugins and themes current from Dashboard → Updates, turn on automatic updates for plugins you trust, and remove the ones you do not use.
  • Backups: a site is its folder plus its database. Dump the database nightly and copy both off the server, as in backing up a database to S3, or to a storage box.
mkdir -p ~/backups
sudo mariadb-dump --single-transaction wordpress | gzip > ~/backups/wordpress-$(date +%F).sql.gz

Moving an existing site from shared hosting? Follow moving from shared hosting to a VPS, and for more than one site on the server, see how many websites a VPS can host.

Common Questions

  • What does WordPress need on the server?

    WordPress.org recommends PHP 8.3 or greater, and MariaDB 10.11 or greater or MySQL 8.4 or greater, with HTTPS, and names Apache or Nginx as the recommended web servers. Ubuntu 24.04 ships PHP 8.3 and MariaDB 10.11, so its own packages meet that.

  • Why does WordPress not send email from my VPS?

    WordPress sends mail through PHP, which tries to deliver it directly on port 25, and outgoing port 25 is blocked on every VPS. Install an SMTP plugin and send through your email provider or a transactional email service on port 587 or 465.

  • Is a VPS faster than shared hosting for WordPress?

    Usually, because the server's memory and PHP workers are yours alone and you can add page caching and an object cache such as Redis. The flip side is that updates, backups and security are now your job.

  • Can one VPS run several WordPress sites?

    Yes. Give each site its own database, database user, folder and Nginx server block. How many fit depends on traffic more than on the number of sites; see how many websites a VPS can host.

Plans and prices

VPS Plans

KVM servers on NVMe storage with full root access, in Ashburn or Dallas, built in minutes.

See all plans
  • Bronze

    3 vCPU · 6 GB RAM · 75 GB NVMe

    2 TB transfer

    $37.50/mo

    Configure inAshburnDallas
  • Silver

    4 vCPU · 8 GB RAM · 100 GB NVMe

    4 TB transfer

    $46.50/mo

    Configure inAshburnDallas
  • Gold

    6 vCPU · 12 GB RAM · 150 GB NVMe

    6 TB transfer

    $60.00/mo

    Configure inAshburnDallas
  • Diamond

    8 vCPU · 16 GB RAM · 200 GB NVMe

    8 TB transfer

    $73.50/mo

    Configure inAshburnDallas

Network port: 10 Gbps in Ashburn, VA, 50 Gbps in Dallas, TX. Pick the location when you configure.

Keep Reading

All guides