Step-by-step guide to install WordPress on a VPS with Ubuntu, PHP 8.3, MariaDB, and Caddy. Learn to self-host WordPress for better performance and control.

Setting up WordPress on your own VPS gives you complete control over your hosting environment, better performance, and significant cost savings compared to managed hosting. In this comprehensive guide, I'll walk you through installing WordPress on an Ubuntu VPS using modern tools: PHP 8.3, MariaDB, and Caddy web server.

If you haven't secured your VPS yet, check out my previous guide on First Things to Do After Buying a VPS before continuing.

Why Choose a VPS for WordPress?#

Before diving into the installation, let's understand why hosting WordPress on a VPS is often better than shared hosting:

  • Full root access to configure everything exactly how you need
  • Better performance with dedicated resources
  • Cost-effective at around $3-5/month for entry-level VPS
  • Scalability to upgrade resources as your site grows
  • Learning experience that deepens your understanding of web hosting

Prerequisites#

Before we begin, make sure you have:

  • A VPS running Ubuntu 22.04 or 24.04 (I recommend Hetzner for affordable options)
  • A domain name pointed to your VPS IP address
  • SSH access to your server
  • Basic command line knowledge

Step 1: Update Your System#

First, connect to your VPS via SSH and update all packages:

Bash
1sudo apt update && sudo apt upgrade -y

Step 2: Install PHP 8.3 and Required Extensions#

WordPress requires PHP along with several extensions. Let's install PHP 8.3 (the latest stable version) with all necessary modules:

Bash
1# Add PHP repository
2sudo add-apt-repository ppa:ondrej/php -y
3sudo apt update
4
5# Install PHP 8.3 and extensions
6sudo apt install php8.3-fpm php8.3-mysql php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip php8.3-gd php8.3-intl php8.3-imagick -y

Verify the installation:

Bash
1php -v

You should see output showing PHP 8.3.x.

Step 3: Install MariaDB Database Server#

MariaDB is a drop-in replacement for MySQL with better performance and is fully compatible with WordPress:

Bash
1sudo apt install mariadb-server -y

Secure your MariaDB installation:

Bash
1sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disallow remote root login, remove test database, and reload privilege tables.

Step 4: Create WordPress Database and User#

Log into MariaDB and create a database and user for WordPress:

SQL
1sudo mysql -u root -p
2
3CREATE DATABASE wordpress_db;
4CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_strong_password_here';
5GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
6FLUSH PRIVILEGES;
7EXIT;
Important: Replace your_strong_password_here with a strong, unique password.

Step 5: Install Caddy Web Server#

Caddy is a modern web server that automatically handles HTTPS certificates via Let's Encrypt. It's much simpler to configure than Apache or Nginx:

Bash
1# Install Caddy
2sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
3curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
4curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
5sudo apt update
6sudo apt install caddy -y

Step 6: Download and Configure WordPress#

Create a directory for your WordPress site and download WordPress:

Bash
1# Create web directory
2sudo mkdir -p /var/www/yoursite
3cd /var/www/yoursite
4
5# Download WordPress
6sudo wget https://wordpress.org/latest.tar.gz
7sudo tar -xzf latest.tar.gz
8sudo mv wordpress/* .
9sudo rm -rf wordpress latest.tar.gz
10
11# Set proper ownership
12sudo chown -R www-data:www-data /var/www/yoursite
13sudo chmod -R 755 /var/www/yoursite

Step 7: Configure Caddy for WordPress#

Edit the Caddyfile to configure your WordPress site:

Bash
1sudo nano /etc/caddy/Caddyfile

Replace the contents with:

caddyfileCaddyfile
1yourdomain.com {
2    root * /var/www/yoursite
3    php_fastcgi unix//run/php/php8.3-fpm.sock
4    file_server
5    
6    @notStatic {
7        not path /wp-admin/* /wp-content/* /wp-includes/*
8        not file
9    }
10    rewrite @notStatic /index.php
11    
12    encode gzip
13}
Replace yourdomain.com with your actual domain name.

Restart Caddy to apply the configuration:

Bash
1sudo systemctl restart caddy

Caddy will automatically obtain and configure an SSL certificate for your domain.

Step 8: Complete WordPress Installation#

Visit your domain in a web browser (e.g., https://yourdomain.com). You'll see the WordPress installation wizard.

  1. Select your language
  2. Enter database details:
    • Database Name: wordpress_db
    • Username: wp_user
    • Password: (the password you created earlier)
    • Database Host: localhost
    • Table Prefix: wp_ (or change for security)
  3. Run the installation
  4. Set up your site with Site Title, Admin Username (don't use "admin"), Password, and Email

Step 9: Post-Installation Security#

After installing WordPress, take these security measures:

Update Security Keys#

Generate new security keys at WordPress Secret Key Generator and add them to your wp-config.php.

Set Proper File Permissions#

Bash
1# Secure wp-config.php
2sudo chmod 600 /var/www/yoursite/wp-config.php

Install Essential Security Plugins#

  • Wordfence or Solid Security for firewall and malware scanning
  • UpdraftPlus for automated backups
  • Limit Login Attempts Reloaded to prevent brute force attacks

Bonus: Local Theme Development Workflow#

You can develop your WordPress theme on your local machine and deploy it to your VPS using rsync:

Bash
1# Sync theme to staging directory
2rsync -avz --delete /local/path/to/theme/ user@your-vps-ip:~/theme-staging/
3
4# Copy to WordPress themes directory
5ssh user@your-vps-ip 'sudo cp -r ~/theme-staging/* /var/www/yoursite/wp-content/themes/your-theme/'

This workflow keeps your production server clean while allowing rapid development on your local machine.

Performance Optimization Tips#

  1. Enable PHP OPcache - Already included in PHP 8.3
  2. Install a caching plugin - WP Super Cache or W3 Total Cache
  3. Use a CDN - Cloudflare offers a free tier
  4. Optimize images - Use ShortPixel or Imagify
  5. Keep WordPress, themes, and plugins updated

Frequently Asked Questions#

How much does it cost to host WordPress on a VPS?#

Entry-level VPS providers like Hetzner offer plans starting at around $3-5/month, which is often cheaper than managed WordPress hosting while giving you more control and dedicated resources.

Is Caddy better than Nginx for WordPress?#

Both are excellent choices. Caddy's main advantage is automatic HTTPS certificate management and simpler configuration. Nginx offers more fine-grained control but requires more setup. For most WordPress sites, Caddy is easier to manage.

Why use PHP 8.3 instead of older versions?#

PHP 8.3 offers significant performance improvements (up to 20% faster than PHP 7.4), better security, and new features. WordPress fully supports PHP 8.3, and most modern plugins are compatible.

Can I host multiple WordPress sites on one VPS?#

Yes! Simply create separate directories for each site, set up additional databases, and add multiple site blocks in your Caddyfile. A $5/month VPS can easily handle 3-5 low-traffic WordPress sites.

How do I update WordPress on a VPS?#

WordPress has a built-in auto-update feature. You can also update manually through the admin dashboard or via WP-CLI:

Bash
1wp core update
2wp plugin update --all
3wp theme update --all

What if I get locked out of my WordPress admin?#

You can reset your password directly in the database:

SQL
1sudo mysql -u root -p
2USE wordpress_db;
3UPDATE wp_users SET user_pass = MD5('newpassword') WHERE user_login = 'yourusername';

Conclusion#

You now have a fully functional WordPress installation running on your VPS with PHP 8.3, MariaDB, and Caddy. This setup provides excellent performance, automatic SSL, and complete control over your hosting environment.

Remember to:

  • Keep your server and WordPress updated
  • Maintain regular backups
  • Monitor your server resources
  • Follow security best practices

This foundation gives you the flexibility to customize your hosting setup as your needs grow. Happy hosting!

VPSDevOps ToolsWeb Development