(Last Updated On: September 2, 2018)

This guide is intended to help you install and host your WordPress website using Caddy Web server. Caddy is an open-source, production-ready that is build to be fast, easy to use, and makes you more productive. Caddy is available for Windows, Mac, Linux, BSD, Solaris, and Android.

If you don’t have Caddy Web server installed, use our guide Install Caddy web server on an Ubuntu 18.04 with Let’s Encrypt SSL to set it up.

For Nginx users, see How to Setup WordPress Multisite Network with Nginx and Let’s Encrypt 

Once you have Caddy web server up and running, proceed to configure it for WordPress hosting:

Using Caddy Web Server to host WordPress Website

In this section, we will install and configure WordPress to be powered by Caddy web server.

To run a WordPress website, you need PHP, Web server, and Database server

sudo apt -y update
sudo apt -y install php-fpm php-mysql php-curl php-gd php-mbstring php-common php-xml php-xmlrpc

For CentOS 7 server run:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install epel-release
sudo yum install yum-utils
sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php72
sudo yum -y install php-cli php-fpm php-mysql php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath

Install and Configure MariaDB Database server

Install and configure MariaDB database server using:

Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7

Once done, login as root user and create a database for WordPress

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 520
Server version: 10.3.9-MariaDB-1:10.3.9+maria~bionic-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE wp_site;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wp_site.* to 'wp_user'@'localhost' IDENTIFIED BY 'StrongPassword';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> quit
Bye

Download WordPress and Install

Now download WordPress and untar the archive

wget http://wordpress.org/latest.tar.gz
tar xvf latest.tar.gz

This will extract all content of the tarball to a folder named wordpress on your working directory.

Move the wordpress folder to /var/www directory

sudo mv wordpress /var/www

Change ownership permissions to userwww-data and group.

sudo chown -R www-data:www-data /var/www/wordpress

Configure WordPress database connection

mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

Edit the file to configure

sudo vim /var/www/wordpress/wp-config.php

Set below variables

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wp_site');

/** MySQL database username */
define('DB_USER', 'wp_user');

/** MySQL database password */
define('DB_PASSWORD', 'StrongPassword');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Configuring Caddy to Serve the WordPress Site

We have WordPress installation ready, we now need to configure Caddy Web server to serve our WordPress website. Start by creating a Caddy configuration file on /etc/caddy/Caddyfile

sudo vim /etc/caddy/Caddyfile

Add the content

example.com {
    tls [email protected]
    root /var/www/wordpress
    gzip
    fastcgi / /run/php/php7.2-fpm.sock php
    rewrite {
        if {path} not_match ^\/wp-admin
        to {path} {path}/ /index.php?{query}
    }
}

Replace example.com with your actual domain for WordPress website and [email protected] with an actual email address used to request Let’s Encrypt certificate. We’re using php-fpm via fastcgi to support php.

Start caddy service

sudo systemctl start caddy.service

If the start was successful, you should get a successful message:

# systemctl status caddy
● caddy.service - Caddy HTTP/2 web server
   Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-09-02 14:34:26 EAT; 7s ago
     Docs: https://caddyserver.com/docs
 Main PID: 32443 (caddy)
    Tasks: 12 (limit: 4704)
   CGroup: /system.slice/caddy.service
           └─32443 /usr/local/bin/caddy -log /var/log/caddy.log -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp

Sep 02 14:34:26 wp.computingforgeeks.com systemd[1]: Started Caddy HTTP/2 web server.
Sep 02 14:34:34 wp.computingforgeeks.com caddy[32443]: Activating privacy features... done.
Sep 02 14:34:34 wp.computingforgeeks.com caddy[32443]: https://wp.computingforgeeks.com
Sep 02 14:34:34 wp.computingforgeeks.com caddy[32443]: http://wp.computingforgeeks.com

Access the WordPress dashboard by visiting.https://example.com You should get initial wordpress setup page.

Provider username and password.

Thank you for reading our guide on how to Install Caddy web server on an Ubuntu 18.04 with Let’s Encrypt SSL. I like Caddy simplicity, robustness and the fact that it uses HTTPS by default. No routing and redirects needed to host your website.