Install WordPress with Caddy on a VPS to run a self-hosted site behind HTTPS, with Caddy obtaining and renewing certificates automatically. You’ll install a web server, PHP, and a database, then connect them to WordPress; you’ll need a domain pointed at the server and SSH access.
What You’ll Need
- A VPS running a current Ubuntu LTS release, with a public IPv4 address. The commands below assume Ubuntu and a user with sudo access.
- A domain or subdomain with DNS A records pointing to the VPS. Add an AAAA record only if IPv6 is configured and reachable on the server.
- SSH access, plus permission to allow inbound TCP traffic on ports 80 and 443 in both the VPS firewall and any provider firewall.
- A strong, unique database password and a plan to keep WordPress, Ubuntu, and backups updated.
Step-by-Step
- Connect and update the VPS. From your computer, connect with
ssh username@YOUR_SERVER_IP, replacing the placeholders. Update packages withsudo apt update && sudo apt upgrade -y. If the upgrade installs a new kernel, reboot withsudo rebootand reconnect. - Point DNS to the server. At your DNS provider, create an A record for your domain, such as
example.com, with the VPS IPv4 address. If you wantwww.example.com, create a matching record forwww. DNS changes can take time to appear. Confirm the records resolve to this server before proceeding. - Install Caddy, PHP-FPM, and MariaDB. Install Caddy from its official Debian/Ubuntu package repository so it receives maintained packages. Follow the current installation instructions at
caddyserver.com/docs/installfor Debian/Ubuntu; then install the required services and PHP extensions:sudo apt install mariadb-server php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zip
Check the installed PHP-FPM socket name withls /run/php/. It will resemblephp8.3-fpm.sock; use the actual filename in the Caddy configuration below. - Create a database and database user. Open MariaDB’s local console:
sudo mariadb
Run the following, replacingCHOOSE_A_LONG_RANDOM_PASSWORDwith a unique password. Keep the password safe and do not use the example text literally:CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'CHOOSE_A_LONG_RANDOM_PASSWORD';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT; - Download WordPress into its web directory. Create a directory and download the current release from WordPress.org:
sudo mkdir -p /var/www/example.com
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo cp -a wordpress/. /var/www/example.com/
Replaceexample.comwith your domain. Give the web server read access and the ability to write where WordPress needs it: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 {} \; - Configure Caddy for your domain and PHP. Edit the Caddyfile with
sudo nano /etc/caddy/Caddyfile. Replace its contents with the following, using your actual domain and PHP socket:example.com, www.example.com {
root * /var/www/example.com
php_fastcgi unix//run/php/php8.3-fpm.sock
file_server
}
If you did not configure the www DNS record, removewww.example.com. Check the configuration and reload Caddy:sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy - Allow web traffic and verify services. If you use UFW, allow SSH before enabling it so you do not lock yourself out. Then allow web traffic with
sudo ufw allow 80/tcpandsudo ufw allow 443/tcp. Check status withsudo systemctl status caddy mariadband confirm provider-level firewall rules also allow ports 80 and 443. Caddy can obtain a certificate when the domain resolves correctly and the server is reachable. - Finish WordPress setup in your browser. Visit
https://example.com. Select a language, then enter database namewordpress, usernamewpuser, the password you created, and database hostlocalhost. Complete the site title and administrator account. Use a unique administrator username and strong password; store the credentials securely.
Common Mistakes
- Wrong PHP-FPM socket: A hard-coded version may not match the installed PHP package. Check
/run/php/and update the Caddyfile accordingly. - DNS is not ready: A mistyped address, missing www record, or stale DNS can prevent HTTPS setup. Check each hostname independently before troubleshooting certificates.
- Ports are blocked: Opening UFW is not enough if the VPS provider has a separate firewall. Allow inbound TCP 80 and 443 in both places.
- Database credentials do not match: The WordPress installer needs the exact database name, username, and password created in MariaDB. Avoid special quoting errors when entering SQL passwords.
- Overly broad file permissions: Do not use
chmod 777. It gives every local user write access; use the ownership and permissions in the steps above.
Tips
- Take a VPS snapshot before major upgrades, and maintain separate backups of the database and WordPress files. Test that you can restore them.
- Use a non-root SSH account with sudo, keep SSH access protected, and apply operating-system and WordPress updates promptly.
- After installation, use HTTPS consistently and check WordPress’s Site Address and WordPress Address under Settings if you change the domain.
- Keep plugins and themes to those you need. Remove unused ones and back up before updating them.
Troubleshooting
If the site does not load, first confirm the domain points to the VPS and that ports 80 and 443 are allowed. Check Caddy’s logs with sudo journalctl -u caddy --no-pager -n 50. For PHP errors, check the PHP-FPM service with systemctl list-units 'php*-fpm.service' and inspect its status using the service name shown. Recheck that the socket path in the Caddyfile matches the installed socket, then run sudo caddy validate --config /etc/caddy/Caddyfile before reloading.
If HTTPS is not issued, make sure DNS has propagated, both A and any configured AAAA records lead to this VPS, and inbound ports 80 and 443 are reachable. If the installer reports a database connection error, test that MariaDB is running and carefully re-enter the database values. A 403 or 404 often points to a wrong document root, missing WordPress files, or incorrect ownership; verify the directory path and permissions. After changes, reload Caddy with sudo systemctl reload caddy and refresh the page.
Frequently Asked Questions
Does Caddy install WordPress for me?
No. Caddy serves the site and manages HTTPS certificates; you still install PHP and a database, place WordPress files, and complete its browser-based setup.
Do I need a domain name?
A domain is strongly recommended for a normal public WordPress site and automatic publicly trusted HTTPS. Point its DNS records to the VPS before relying on certificate issuance.
Can I use MySQL instead of MariaDB?
Yes. WordPress supports MySQL as well as compatible database servers such as MariaDB. Install one database server, create a database and user, and enter its credentials in the installer.
Why does the site work over HTTP but not HTTPS?
Check that DNS resolves correctly and TCP port 443 is open in both the server and provider firewalls. Review Caddy’s service logs for certificate or configuration errors.
Where should I put the PHP socket path?
Use the socket shown in /run/php/ after PHP-FPM is installed. The version in the example is only an example and may differ on your VPS.
How do I update Caddy’s configuration safely?
Edit the Caddyfile, validate it with sudo caddy validate --config /etc/caddy/Caddyfile, and reload only after validation succeeds. If validation fails, correct the reported syntax issue first.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km
- Connect Phone to Controller for Cloud Gaming
- Python Search Highlighting: Snippets & Matches