How to Host a WordPress Site on a VPS: Step-by-Step Tutorial

How to Host a WordPress Site on a VPS: Step-by-Step Tutorial

This tutorial walks you through the entire process from a blank Ubuntu 22.04 VPS to a fully running, SSL-secured WordPress site. No prior server experience required.

🐧Ubuntu 22.04
Operating System
Nginx
Web Server
🐘PHP 8.3
Backend
🐬MySQL 8
Database
🔒Let’s Encrypt
Free SSL

Before You Begin

Make sure you have the following ready before starting:

🖥VPS with Ubuntu 22.04
Min: 1 GB RAM, 1 vCPU, 20 GB SSD
🌐A Domain Name
Pointed to your VPS IP via A record
🔑SSH Access
Root or sudo user credentials
💡If you haven’t secured your VPS yet, follow our 10-Step VPS Security Guide first. It only takes 30 minutes and will protect your server before you add a live website to it.

STEP 1
Update System & Install Nginx
⏱ ~3 min

Start with a clean, updated system. Then install Nginx — the web server that will handle all HTTP/HTTPS traffic to your WordPress site.

bash
# Update packages
$ apt update && apt upgrade -y

# Install Nginx
$ apt install nginx -y

# Start and enable Nginx
$ systemctl start nginx
$ systemctl enable nginx

# Allow HTTP/HTTPS through firewall
$ ufw allow 'Nginx Full'

Verify Nginx is running by visiting your server’s IP address in a browser. You should see the default Nginx welcome page.

STEP 2
Install PHP 8.3
⏱ ~5 min

WordPress requires PHP. We’ll install PHP 8.3 along with the extensions WordPress depends on. We use php-fpm (FastCGI Process Manager) to integrate PHP with Nginx.

bash
# Add PHP repository
$ apt install software-properties-common -y
$ add-apt-repository ppa:ondrej/php -y
$ apt update

# Install PHP 8.3 and required extensions
$ 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-bcmath php8.3-imagick -y

# Verify PHP version
$ php -v
💡The ondrej/php PPA is the most reliable source for up-to-date PHP versions on Ubuntu. It’s maintained by one of the official PHP package maintainers.

STEP 3
Install MySQL & Create a Database
⏱ ~5 min

WordPress stores all its data — posts, settings, users — in a MySQL database. Install MySQL, secure it, then create a dedicated database and user for WordPress.

bash
# Install MySQL
$ apt install mysql-server -y

# Run the security script
$ mysql_secure_installation

Follow the prompts: set a root password, remove anonymous users, disallow remote root login, and remove the test database.

Now create the WordPress database and user:

mysql
$ mysql -u root -p

-- Create the database
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create a dedicated user
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';

-- Grant permissions
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
⚠️Replace StrongPassword123! with a unique, strong password. Save your database name, username, and password — you’ll need them in Step 4.

STEP 4
Download & Configure WordPress
⏱ ~4 min

Download the latest WordPress release directly from wordpress.org and place it in your web root directory.

bash
# Download latest WordPress
$ cd /tmp
$ wget https://wordpress.org/latest.tar.gz
$ tar -xzf latest.tar.gz

# Move to web root
$ mv wordpress /var/www/yourdomain.com

# Create wp-config.php from the sample
$ cp /var/www/yourdomain.com/wp-config-sample.php \
     /var/www/yourdomain.com/wp-config.php

Edit the config file with your database credentials:

bash
$ nano /var/www/yourdomain.com/wp-config.php
php — wp-config.php
define( 'DB_NAME',     'wordpress_db' );
define( 'DB_USER',     'wp_user' );
define( 'DB_PASSWORD', 'StrongPassword123!' );
define( 'DB_HOST',     'localhost' );

Also update the secret keys by fetching fresh ones from https://api.wordpress.org/secret-key/1.1/salt/ and replacing the placeholder block in wp-config.php.

STEP 5
Configure Nginx for WordPress
⏱ ~5 min

Create an Nginx server block (virtual host) for your domain. This tells Nginx how to route requests to your WordPress installation.

bash
$ nano /etc/nginx/sites-available/yourdomain.com

Paste the following configuration (replace yourdomain.com with your actual domain):

nginx
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.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.3-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    # Cache static assets
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
        expires 30d;
        add_header Cache-Control "public, no-transform";
    }
}
bash
# Enable site and test config
$ ln -s /etc/nginx/sites-available/yourdomain.com \
        /etc/nginx/sites-enabled/
$ nginx -t
$ systemctl reload nginx

STEP 6
Set Correct File Permissions
⏱ ~2 min

WordPress needs specific file permissions to function securely. The web server user (www-data) must own the WordPress files so it can read them and write uploads.

bash
# Set ownership
$ chown -R www-data:www-data /var/www/yourdomain.com

# Set directory permissions
$ find /var/www/yourdomain.com -type d -exec chmod 755 {} \;

# Set file permissions
$ find /var/www/yourdomain.com -type f -exec chmod 644 {} \;
🚨Never set WordPress files to 777. This allows any process on the server to write to your files and is a serious security vulnerability. Stick to 755 for directories and 644 for files.

STEP 7
Install Free SSL with Certbot (Let’s Encrypt)
⏱ ~5 min

HTTPS is mandatory in 2025 — it affects both your Google rankings and user trust. Let’s Encrypt provides free, auto-renewing SSL certificates via Certbot.

bash
# Install Certbot
$ apt install certbot python3-certbot-nginx -y

# Obtain and install SSL certificate
$ certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot will automatically edit your Nginx config to enable HTTPS and set up a redirect from HTTP. It also installs a cron job to auto-renew the certificate before it expires.

Test the auto-renewal:

bash
$ certbot renew --dry-run
After Certbot runs, your site will be accessible at https://yourdomain.com with a valid SSL certificate and automatic HTTP → HTTPS redirect.

STEP 8
Complete WordPress Setup in the Browser
⏱ ~3 min

The technical setup is done. Now finish the WordPress installation through its web interface.

  1. Visit https://yourdomain.com in your browser
  2. Select your language and click Continue
  3. Enter your site title, admin username, a strong password, and your email
  4. Click Install WordPress
  5. Log in at https://yourdomain.com/wp-admin
🎉Your WordPress site is now live on your VPS! You have full server control, dedicated resources, and a free auto-renewing SSL certificate.

BONUS
Performance Tuning: Make WordPress Faster
⏱ Optional

With your VPS, you have tools unavailable on shared hosting. Here are three quick wins that significantly improve WordPress performance:

Enable PHP OPcache

OPcache stores compiled PHP code in memory, eliminating the need to recompile scripts on every request.

bash
$ nano /etc/php/8.3/fpm/php.ini

# Find and set:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2

Install Redis Object Cache

Redis caches WordPress database queries in memory, dramatically reducing response times for dynamic pages.

bash
$ apt install redis-server php8.3-redis -y
$ systemctl enable redis-server

Then install the Redis Object Cache plugin in your WordPress dashboard and enable it.

Use Cloudflare (Free CDN + DDoS Protection)

Point your domain’s nameservers to Cloudflare. Their free plan provides global CDN caching, DDoS mitigation, and an extra SSL layer — all with zero additional cost.

Frequently Asked Questions

Can I use Apache instead of Nginx for WordPress?
Yes. Apache is also a solid choice for WordPress, especially if you’re familiar with .htaccess rules. Nginx generally uses less memory and performs better under high concurrent traffic, which is why it’s the recommended choice for VPS setups.
What’s the minimum VPS size for running WordPress?
A 1 GB RAM, 1 vCPU VPS can run a lightly-trafficked WordPress site. For a production site with consistent traffic or WooCommerce, we recommend at least 2 GB RAM and 2 vCPUs. Add Redis and OPcache (covered above) to get the most out of limited resources.
How do I migrate an existing WordPress site to my VPS?
Use a migration plugin like All-in-One WP Migration or Duplicator. Export your site, install WordPress on the VPS using this guide, then import the backup. Update your domain’s DNS A record to point to the new VPS IP once everything is tested.
Do I need a control panel like cPanel or Plesk?
Not necessarily. This guide sets everything up via the command line, which is more lightweight and gives you more control. If you prefer a GUI, free alternatives like HestiaCP or CyberPanel work well and support Nginx + WordPress setups.
How do I set up automatic WordPress backups?
Install the UpdraftPlus plugin for automated WordPress file and database backups to remote storage (Google Drive, S3, Dropbox). Also set up server-level snapshots through your VPS provider’s dashboard as a secondary safety net.

🚀 Your WordPress Site is Live on a VPS

You’ve gone from a blank server to a fully functional, SSL-secured WordPress site with a production-grade stack: Nginx, PHP 8.3, MySQL 8, and Let’s Encrypt. That’s the same setup used by professional developers and agencies around the world.Next steps: lock down your WordPress installation (limit login attempts, disable XML-RPC, add two-factor authentication for admin), install a caching plugin, and set up automated backups. Your site is now running on infrastructure you fully own and control.

 

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!