VPS

How to Install WordPress on a VPS (Ubuntu + Nginx, Step by Step)

12 min read

How to Install WordPress on a VPS (Ubuntu + Nginx, Step by Step)

What You Will Get

By the end of this tutorial you will have a WordPress site running on your own VPS: Ubuntu 24.04, Nginx, PHP 8.3, MySQL and a free Let’s Encrypt SSL certificate — the stack professionals call LEMP. No control panel, no monthly panel fee, and full control over every setting.

The whole process takes about 30–45 minutes if you follow the steps in order. You need a VPS with at least 1 GB of RAM (2 GB recommended), a domain name pointed at your server’s IP address, and a terminal with SSH access. If you have not picked a server yet, our how to choose a VPS guide covers the decision, and our best VPS for WordPress guide lists the best-value servers for this exact job. If your domain is not pointed at the server yet, do that first with our how to point a domain to your VPS guide — DNS changes can take up to a few hours to spread, and SSL setup will fail until they do.

Run every command as a user with sudo access, not as root directly. If you have just created your server, work through our how to secure your VPS guide first — it takes 30 minutes and covers SSH keys, a firewall and automatic updates. A WordPress site on an unsecured server is a matter of time, not luck.

Step 1: Update the Server

Connect to your server over SSH, then update the package lists and upgrade installed packages:

sudo apt update && sudo apt upgrade -y

This takes a few minutes on a fresh server. Reboot if the upgrade installed a new kernel:

sudo reboot

Then reconnect and continue. Keeping the base system current before you install anything else avoids a whole class of strange failures later.

Step 2: Install Nginx

Nginx is the web server — it listens on ports 80 and 443 and serves your site to visitors. Install it from Ubuntu’s repositories:

sudo apt install nginx -y

Start it and set it to start automatically at boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Check it is running:

sudo systemctl status nginx

You should see active (running). Now open your server’s IP address in a browser — you should see the Nginx welcome page. If you see nothing, your firewall is probably blocking port 80; allow it:

sudo ufw allow 'Nginx Full'

Nginx Full opens both port 80 (HTTP) and 443 (HTTPS). You will need both once SSL is set up.

Step 3: Install MySQL and Create the Database

WordPress stores all its content in a MySQL database. Install the server:

sudo apt install mysql-server -y

Secure the installation and set a root password when prompted:

sudo mysql_secure_installation

Answer yes to removing anonymous users, disallowing remote root login, removing the test database, and reloading the privilege tables. Then log in to MySQL:

sudo mysql

Create a database and a dedicated user for WordPress. Replace strongpassword with a real password — generate one with a password manager, do not reuse anything:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Note the character set: utf8mb4 supports emoji and the full range of characters your content might use. The older utf8 in MySQL is a limited 3-byte version that breaks emoji — always use utf8mb4 for a new WordPress install.

Step 4: Install PHP 8.3 and Required Extensions

Ubuntu 24.04 ships PHP 8.3, which is the version WordPress currently recommends. Install PHP-FPM (the process manager Nginx talks to) and the extensions WordPress needs:

sudo apt install php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-intl php8.3-bcmath php8.3-imagick -y

Check the PHP version:

php -v

You should see PHP 8.3.x. PHP-FPM starts automatically after installation; verify it:

sudo systemctl status php8.3-fpm

Two configuration tweaks are worth making now, before WordPress is installed. Open the PHP-FPM configuration:

sudo nano /etc/php/8.3/fpm/php.ini

Find and change these three values (use Ctrl+W to search in nano):

upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M

The defaults (2 MB uploads, 128 MB memory) are too small for a modern WordPress site — a 2 MB upload limit blocks most theme and plugin uploads. Save with Ctrl+O, Enter, then Ctrl+X, and restart PHP-FPM:

sudo systemctl restart php8.3-fpm

Step 5: Configure Nginx for WordPress

Create a server block (virtual host) for your domain. Replace example.com with your domain throughout:

sudo nano /etc/nginx/sites-available/example.com

Paste this configuration:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php index.html index.htm;

    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 ~ /\.ht {
        deny all;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        log_not_found off;
        access_log off;
    }
}

The try_files line is the important one: it tells Nginx to hand any URL that is not a real file to WordPress’s index.php, which is how pretty permalinks work. Without it, every page except the homepage returns a 404.

Enable the site and disable the default:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default

Test the configuration before reloading — Nginx will tell you about syntax errors instead of failing silently:

sudo nginx -t

If the test passes, reload Nginx:

sudo systemctl reload nginx

Step 6: Download and Install WordPress

Create the web directory and download the latest WordPress:

sudo mkdir -p /var/www/example.com
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo cp -a /tmp/wordpress/. /var/www/example.com/

Set ownership so Nginx and PHP can read and write the files. On Ubuntu, the web server runs as www-data:

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

Now create the WordPress configuration file. WordPress ships a sample — copy it and edit in your database details:

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

Change these three lines to match the database and user you created in Step 3:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'strongpassword' );

Then replace the eight put your unique phrase here security keys. Generate fresh keys from WordPress.org’s secret-key service and paste them in — never leave the placeholder text in place, and never reuse keys from another site:

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

Copy the output into wp-config.php, replacing the eight placeholder define lines. Save and exit.

Step 7: Run the WordPress Installer

Open http://example.com in your browser. You should see the WordPress installation screen. Pick your language, then fill in:

  • Site Title — your site’s name (changeable later).
  • Username — do not use admin. Pick something unique; the admin username is half of a login, and admin is the first guess every bot tries.
  • Password — generate a strong one and store it in a password manager.
  • Your Email — used for password resets and notifications.
  • Search engine visibility — leave this unchecked unless you specifically want to hide the site while you build it.

Click Install WordPress, then log in at http://example.com/wp-admin. Your site is live — over plain HTTP for now. The next step fixes that.

Step 8: Add Free SSL with Let’s Encrypt

HTTPS is not optional in 2026: browsers flag plain-HTTP sites, and Google uses HTTPS as a ranking signal. Certbot automates the whole process:

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

Certbot will ask for an email address (for expiry reminders), ask you to agree to the terms, and ask whether to redirect HTTP to HTTPS — choose redirect. It then obtains a certificate, rewrites your Nginx configuration, and reloads the server. Visit https://example.com and check for the padlock icon.

Certificates renew automatically: Certbot installs a systemd timer that checks twice a day and renews any certificate within 30 days of expiry. Verify the timer exists:

sudo systemctl status certbot.timer

And test the renewal process without actually renewing:

sudo certbot renew --dry-run

If the dry run passes, SSL is done — you never need to think about it again unless the timer breaks. Our how to set up free SSL with Let’s Encrypt guide covers edge cases like multiple domains and manual renewal.

Step 9: Essential First Settings

Before you write your first post, five things:

  1. Permalinks: in wp-admin, go to Settings → Permalinks and choose Post name. The default ?p=123 URLs are bad for SEO and ugly to share.
  2. Timezone and language: Settings → General — set your timezone and site language.
  3. Delete the defaults: remove the “Hello world!” post, the sample comment, and any default plugins you do not need.
  4. Install a caching plugin: on a VPS, caching is what turns a fast server into a fast site. A free plugin (WP Super Cache or LiteSpeed Cache) plus Nginx is enough for most blogs. Our how to speed up your VPS guide covers server-side caching too.
  5. Set up backups now, not later. A server without backups is a site waiting to disappear. Our how to back up your VPS guide shows how to automate WordPress + database backups off the server.

Troubleshooting

“502 Bad Gateway” after installation

PHP-FPM is not running, or Nginx is pointing at the wrong socket. Check PHP-FPM’s status (sudo systemctl status php8.3-fpm), restart it, and verify the socket path in your Nginx config matches the installed PHP version: /run/php/php8.3-fpm.sock. If you installed a different PHP version, the socket name changes with it.

“404 Not Found” on every page except the homepage

Your Nginx try_files line is missing or wrong. It must read try_files $uri $uri/ /index.php?$args; inside the location / block. After fixing it, run sudo nginx -t and reload Nginx.

“Error establishing a database connection”

WordPress cannot reach MySQL. Check three things: the database name, user and password in wp-config.php match what you created in Step 3; MySQL is running (sudo systemctl status mysql); and the wpuser account has privileges on the wordpress database. The most common cause is a typo in the password — retype it rather than re-reading it.

Certbot fails with a challenge error

Let’s Encrypt could not reach your server. The usual causes: DNS has not propagated yet (wait and retry — check with dig +short example.com from another machine), port 80 is blocked by the firewall, or the Nginx server block’s server_name does not match the domain you passed to Certbot. Certbot needs plain HTTP on port 80 to work, even though the end goal is HTTPS.

File uploads fail or themes will not install

Almost always a permissions problem. The web directory must be owned by www-data (see Step 6). If you uploaded files as your SSH user, they belong to that user, not the web server. Re-run the chown command. If uploads fail with a size error, check upload_max_filesize in php.ini (Step 4) and restart PHP-FPM after changing it.

White screen after installing a plugin or theme

A PHP fatal error with error display turned off. Rename the plugin’s folder over SSH to disable it — sudo mv /var/www/example.com/wp-content/plugins/broken-plugin /var/www/example.com/wp-content/plugins/broken-plugin-off — and the site will come back. Then check the PHP error log to find the cause before reactivating.

Frequently Asked Questions

How much RAM do I need to run WordPress on a VPS?

2 GB is the comfortable minimum for WordPress with a few plugins. 1 GB works for a very light site, but you will need a swap file and careful plugin choices. 4 GB is the right starting point for WooCommerce or a page builder. Our best VPS for WordPress guide ranks servers by this exact requirement.

Should I use Nginx or Apache for WordPress?

Nginx, for a new install. It uses less memory under load, handles many simultaneous connections efficiently, and is the standard for high-traffic WordPress sites. Apache is fine too — and easier if you rely on .htaccess rules — but Nginx is the better default in 2026.

Can I host multiple WordPress sites on one VPS?

Yes. Create a separate server block and directory for each domain, and a separate database and database user for each site. Our how to host multiple websites on one VPS guide walks through the full setup.

Do I need a control panel like cPanel?

No. This tutorial installs everything directly, which is free and gives you full control. A panel is worth paying for only if you manage many sites for clients and want per-account logins — in that case, compare Cloudways or ScalaHosting rather than buying cPanel for a single site.

How do I keep WordPress secure on a VPS?

Update WordPress core, themes and plugins promptly; use strong, unique passwords and two-factor authentication for admin accounts; keep the server itself updated and firewalled; and take off-server backups. Our how to secure your VPS guide covers the server side in detail.

What if I outgrow this setup?

Scale in this order: add RAM to the server, add a caching layer (Redis object cache), move the database to its own server, then add a CDN. Most WordPress sites never need to go past step two. Our how to upgrade your VPS guide covers resizing without downtime.

The Bottom Line

WordPress on a VPS is a 30–45 minute job: Ubuntu 24.04, Nginx, PHP 8.3, MySQL, the WordPress files, and a free Let’s Encrypt certificate. The steps that matter most are the ones people skip — securing the server first, using utf8mb4 for the database, generating real secret keys, and setting up backups before you publish. Do those, and you have a fast, cheap, fully controlled WordPress site for the price of a $5–6 VPS.

Leave a Reply

Your email address will not be published. Required fields are marked *