Installing Caddy Server
Caddy is available in the Ubuntu repository and can be installed directly:
sudo apt update
sudo apt install caddy
Setting Up PHP and MySQL
WordPress requires PHP and MySQL to function. Install the necessary packages:
sudo apt install php php-fpm php-mysql mysql-server
After installation, verify that PHP-FPM is running:
sudo systemctl status php*-fpm
Deploying WordPress
Download the latest WordPress release and extract it to the web root:
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo rm latest.tar.gz
Set appropriate ownership for the WordPress directory:
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Configuring Caddy
Create or edit the Caddy configuration file at /etc/caddy/Caddyfile:
example.com {
root * /var/www/html/wordpress
php_fastcgi unix//run/php/php*-fpm.sock
encode gzip
file_server
handle_errors {
respond "{err.status_code} {err.status_text}"
}
}
Replace example.com with your actual domain name. The php*-fpm.sock wildcard matches your installed PHP version.
Validate the configuration:
sudo caddy validate --config /etc/caddy/Caddyfile
Starting the Server
Enable and start Caddy:
sudo systemctl enable caddy
sudo systemctl start caddy
Verify the service is running:
sudo systemctl status caddy
Data base Setup
Access MySQL and create a database for WordPress:
sudo mysql
CREATE DATABASE wp_database;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Completing Installation
Navigate to your domain in a web browser. The WordPress installation wizard will prompt you to enter:
- Database name:
wp_database - Username:
wp_user - Password:
secure_password - Database host:
localhost - Table prefix:
wp_
Follow the on-screen instructions to complete the setup.
Troubleshooting
If WordPress dislpays permission errors, ensure the web server user has write access to the directory:
sudo chown -R www-data:www-data /var/www/html/wordpress
For HTTPS configuration, Caddy automatically provisions Let's Encrypt certificates when your domain points to the server.