How to Install WordPress with Caddy on Ubuntu 24.04
Caddy is an open-source web server designed for simplicity and automation. Built with Go, Caddy offers attractive features, including built-in support for HTTPS via Let’s Encrypt, automatic certificate management, and simple configuration. Thanks to these features, Caddy has become an ideal choice for developers who need a quick and reliable solution for serving websites or applications.
Install MariaDB
Install MariaDB:
1 | sudo apt install mariadb -y |
Login to MariaDB:
1 | sudo mysql |
Create a database for WordPress:
1 2 3 4 5 | CREATE DATABASE wordpress; CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'secret'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost'; FLUSH PRIVILEGES; exit |
Install PHP
Install PHP 8.3:
1 2 3 4 | sudo apt install php8.3 php8.3-fpm php8.3-cli php8.3-common \ php8.3-apcu php8.3-mbstring php8.3-gd php8.3-intl \ php8.3-xml php8.3-soap php8.3-bcmath php8.3-mysql php8.3-zip \ php8.3-curl php8.3-tidy php8.3-imagick php-pear -y |
Open the PHP-FPM pool configuration file:
1 | sudo nano /etc/php/8.3/fpm/pool.d/www.conf |
Adjust the following configuration:
1 2 3 4 | user = caddy group = caddy listen.owner = caddy listen.group = caddy |
Restart the PHP-FPM service:
1 | sudo systemctl restart php8.3-fpm |
Install WordPress
Install WP-CLI:
1 2 | sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp sudo chmod +x /usr/local/bin/wp |
Create a directory for the domain aminlabs.my.id:
1 2 | sudo mkdir -p /var/www/aminlabs.my.id cd /var/www/aminlabs.my.id |
Download the WordPress core:
1 | sudo wp core download --allow-root |
Create the wp-config.php:
1 2 3 4 5 6 | sudo wp config create \ --dbname="wordpress" \ --dbuser="wordpress" \ --dbpass="secret" \ --dbhost="localhost" \ --allow-root |
Install WordPress:
1 2 3 4 5 6 7 | sudo wp core install \ --url="https://www.aminlabs.my.id" \ --title="AminLabs" \ --admin_user="aminlabs" \ --admin_password="secret" \ --allow-root |
Change the directory ownership:
1 | sudo chown -R caddy:caddy /var/www/aminlabs.my.id |
Install Caddy
Add the GPG key, repository, and install Caddy:
1 2 3 4 5 | sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy -y |
Open the Caddyfile configuration file:
1 2 | cd /etc/caddy sudo nano Caddyfile |
Delete its contents, then enter the configuration for aminlabs.my.id and PHP-FPM:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | www.aminlabs.my.id { tls admin@aminlabs.my.id root * /var/www/aminlabs.my.id php_fastcgi unix//run/php/php8.3-fpm.sock file_server encode gzip log { output file /var/log/caddy/aminlabs.my.id.log } } aminlabs.my.id { redir https://www.aminlabs.my.id{uri} permanent } |
Validate the configuration:
1 | sudo caddy validate |
If there are warning messages:
1 | WARN Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies |
run the following command:
1 | sudo caddy fmt --overwrite |
Restart the Caddy service:
1 | sudo systemctl restart caddy |
Testing
Finally, test the installation and configuration by accessing the domain aminlabs.my.id.
- The WordPress website should appear and the HTTPS protocol should be active.
- Log in to the dashboard, test installing and deleting themes.
- Change the permalink to test the URL rewrite.
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin