Complete Beginner’s Guide: Installing WordPress on Ubuntu VPS (2026 Edition)

Assumed environment: Fresh Ubuntu 22.04 or 24.04 LTS VPS Web server: Nginx + PHP-FPM + MariaDB Goal: Secure WordPress site with free Let’s Encrypt SSL

Step 0 – First Things First (Update & Basic Security)

Bash

# Log in as root or use sudo for every command

apt update && apt upgrade -y
apt install -y curl wget nano unzip htop ufw

Step 1 – Point Your Domain to the VPS (DNS)

Go to your domain provider (Namecheap, GoDaddy, Cloudflare, etc.) → DNS settings

Add these two A records:

text

Type    Name/Host    Value              TTL
A       @            YOUR_VPS_IP        Auto / 300
A       www          YOUR_VPS_IP        Auto / 300

Wait 5–60 minutes. Then verify:

Bash

ping yourdomain.com
ping www.yourdomain.com

Both should show your VPS IP.

Step 2 – Install Nginx, PHP 8.2/8.3, MariaDB & Required PHP Modules

Bash

# Install everything in one command (Ubuntu 22.04 → PHP 8.1, Ubuntu 24.04 → PHP 8.3)

apt install -y nginx mariadb-server php php-fpm php-mysql php-curl \
php-gd php-mbstring php-xml php-zip php-soap php-intl php-imagick \
php-redis php-apcu unzip

# Check which PHP version was installed
php -v

Most common versions in 2025:

  • Ubuntu 22.04 LTS → php8.1-fpm
  • Ubuntu 24.04 LTS → php8.3-fpm

Remember your version (you’ll need it later).

Step 3 – Secure MariaDB

Bash

systemctl enable --now mariadb

mysql_secure_installation

Answer like this:

text

Enter current password for root → press Enter (blank)
Set root password? → Y → choose very strong password
Remove anonymous users? → Y
Disallow root login remotely? → Y
Remove test database and access to it? → Y
Reload privilege tables now? → Y

Step 4 – Create Database & User for WordPress

Replace yoursite, wpuser, and VeryStrongPass123!@# with your own values.

Bash

mysql -u root -p

Then inside MySQL prompt:

SQL

CREATE DATABASE yoursite_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'VeryStrongPass123!@#';

GRANT ALL PRIVILEGES ON yoursite_db.* TO 'wpuser'@'localhost';

FLUSH PRIVILEGES;

EXIT;

Step 5 – Download & Install WordPress Files

Bash

cd /var/www

wget https://wordpress.org/latest.zip

unzip latest.zip

mv wordpress yoursite.com

chown -R www-data:www-data yoursite.com

chmod -R 755 yoursite.com

Step 6 – Create Nginx Configuration

Create file:

Bash

nano /etc/nginx/sites-available/yoursite.com

Paste (change PHP version if needed – check with php -v):

nginx

server {
    listen 80;
    server_name yoursite.com www.yoursite.com;

    root /var/www/yoursite.com;
    index index.php index.html index.htm;

    set $skip_cache 0;

    # POST requests and URLs with query strings should always go to PHP
    if ($request_method = POST) {
        set $skip_cache 1;
    }
    if ($query_string != "") {
        set $skip_cache 1;
    }

    # Don't cache URIs containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
        set $skip_cache 1;
    }

    # Don't use the cache for logged-in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $skip_cache 1;
    }

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;   # ← change to php8.1-fpm.sock or php8.2-fpm.sock if needed
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2?|svg|ttf|eot)$ {
        expires 365d;
        access_log off;
    }
}

Enable site & test config:

Bash

ln -s /etc/nginx/sites-available/yoursite.com /etc/nginx/sites-enabled/
nginx -t

# If it says "syntax is ok" and "test is successful":
systemctl reload nginx

Step 7 – Install Free SSL (Let’s Encrypt)

Bash

apt install -y certbot python3-certbot-nginx

certbot --nginx -d yoursite.com -d www.yoursite.com

Answer questions:

  • Enter email
  • Agree to terms → Y
  • Share email → N (or Y)
  • Redirect HTTP → 2 (Redirect – Make all requests secure)

Certbot will automatically modify your Nginx config to use HTTPS.

Step 8 – Final Browser Installation

Open in browser:

text

https://yoursite.com

Follow the 5-minute WordPress installer:

Database Name → yoursite_db Username → wpuser Password → VeryStrongPass123!@# Database Host → localhost Table Prefix → wp_ (or change for extra security)

Create admin user → use strong password and real email.

Done!

Quick Troubleshooting Commands

Bash

# See Nginx errors
tail -f /var/log/nginx/error.log

# See PHP errors
tail -f /var/log/php*-fpm.log

# Restart services
systemctl restart nginx php*-fpm mariadb

# Check open ports
ss -tuln | grep -E ':80|:443'

Good luck with your new WordPress site! 🚀

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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