How to Host WordPress on an Ubuntu VPS (Nginx, MySQL, PHP & SSL – Step-by-Step)
How to Host WordPress on an Ubuntu VPS (Nginx, MySQL, PHP & SSL)
If you want full control, better performance, and real learning, hosting WordPress on a VPS is the right move.
Shared hosting hides everything. A VPS teaches you how things actually work.
In this guide, you’ll learn how to host WordPress on an Ubuntu VPS using Nginx, MySQL, PHP, and free SSL (Let’s Encrypt) step by step, without skipping critical details.
This tutorial assumes Ubuntu 22.04 LTS, which is the current stable choice for production servers.
What Is a VPS and Why Use It for WordPress?
A VPS (Virtual Private Server) is your own isolated server environment.
Unlike shared hosting:
- You control the OS
- You choose Nginx instead of Apache
- You decide PHP versions
- You can scale anytime
When a VPS makes sense
- You want better performance
- You want to learn backend & DevOps
- You plan to scale later
- You don’t want “black box” hosting
If you’re serious about WordPress, a VPS is worth it.
Prerequisites
Before starting, make sure you have:
- An Ubuntu 22.04 VPS
- SSH access (
rootor sudo user) - A domain name pointing to your VPS IP
- Basic terminal knowledge
Step 1: Update Your Ubuntu Server
Always start clean.
sudo apt update
sudo apt upgrade -y
sudo reboot
Reboot ensures the latest kernel and services are active.
Step 2: Install Nginx (Web Server)
Nginx is lightweight and faster than Apache for most WordPress setups.
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Verify:
systemctl status nginx
Open your server IP in a browser — you should see the Nginx welcome page.
Step 3: Install MySQL (Database)
WordPress needs a database to store content and settings.
sudo apt install mysql-server -y
sudo mysql_secure_installation
Recommended answers:
- Remove anonymous users → Yes
- Disallow remote root login → Yes
- Remove test database → Yes
Create WordPress Database & User
sudo mysql
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 4: Install PHP (Required Extensions)
WordPress works best on PHP 8.1.
sudo apt install php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-zip -y
Verify:
php -v
Step 5: Download WordPress
cd /var/www
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
sudo rm latest.tar.gz
Set permissions:
sudo chown -R www-data:www-data /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress
Step 6: Configure Nginx for WordPress
Create a server block:
sudo nano /etc/nginx/sites-available/wordpress
Paste:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/wordpress;
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.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable it:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 7: Configure WordPress
cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update database details:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'StrongPasswordHere');
define('DB_HOST', 'localhost');
Step 8: Install Free SSL (Let’s Encrypt)
SSL is mandatory in 2025.
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx
Choose:
- Your domain
- Redirect HTTP → HTTPS (Yes)
Test auto-renewal:
sudo certbot renew --dry-run
Step 9: Finish WordPress Setup
Open:
https://yourdomain.com
Complete:
- Site title
- Admin username
- Password
🎉 Your WordPress site is live.
Common Mistakes to Avoid
- Using outdated PHP versions
- Forgetting SSL
- Wrong file permissions
- Installing too many plugins
- Ignoring server updates
Most WordPress “issues” are server misconfigurations.
Final Thoughts
Hosting WordPress on a VPS isn’t just about performance — it’s about control and learning.
Once you understand this setup:
- Scaling becomes easy
- Debugging becomes logical
- You’re no longer dependent on shared hosting support
If you’re serious about WordPress, this is the foundation.
1 comment