Web Hosting

How To Host WordPress website with Caddy Web Server

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. You can also use some of the popular WordPress hosting platforms for your website hosting needs.

If you don’t have Caddy Web server installed, use our guide:

Once you have Caddy web server up and running, proceed to configure it for your WordPress hosting. Caddy and WordPress are best friends for life!.

Using Caddy Web Server to host WordPress website

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

1) Install PHP and extensions

To run a WordPress website, you need PHP, Web server, and Database server. Let’s start with the installation of PHP.

Install PHP on Debian / Ubuntu

Run the following commands to install the default version of PHP available in OS default repositories.

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

Confirm PHP installation:

php -v
PHP 8.3.6 (cli) (built: Jun 13 2024 15:23:20) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Install PHP on Rocky / AlmaLinux 9+8

Add REMI repository which contain most PHP versions and extensions.

  • RHEL 9 based systems
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
  • RHEL 8 based systems
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Reset PHP module.

sudo dnf module reset php -y

Enable the module for PHP you want to install:

# PHP 8.3
sudo dnf module install php:remi-8.3 -y

# PHP 8.2
sudo dnf module install php:remi-8.2 -y

# PHP 8.1
sudo dnf module install php:remi-8.1 -y

When done install PHP and all necessary extensions:

sudo dnf -y install wget php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}

Start and enable PHP-FPM service.

sudo systemctl enable --now php-fpm

2) Install and Configure MariaDB Database

We need to install MariaDB database server that will store data for your wordpress website.

  • Add MariaDB official repository.
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s --
  • Install MariaDB server and client.

Ubuntu / Debian

sudo apt update
sudo apt install mariadb-server mariadb-client

RHEL-based systems

sudo dnf -qy module disable mariadb
sudo dnf module reset mariadb -y
sudo yum install MariaDB-server MariaDB-client MariaDB-backup

Start and enable MariaDB service.

sudo systemctl enable --now mariadb

Login to database shell.

sudo mysql -u root

Create a database for WordPress – here we are creating database called wp_db and user wp_user with password Str)#ngPassW0orD. Substitute the values to suit your environment.

CREATE DATABASE wp_db;
GRANT ALL PRIVILEGES ON wp_db.* to 'wp_user'@'localhost' IDENTIFIED BY 'Str)#ngPassW0orD';
FLUSH PRIVILEGES;
QUIT

3) 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_db');

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

/** MySQL database password */
define('DB_PASSWORD', 'Str)#ngPassW0orD'');

/** 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', '');

4) Configuring Caddy to with WordPress

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

your.domain {
    # good practice to signal on behalf of who 
    # are the certs getting issue
	tls [email protected]

    # logs are optional
	log {
		output file /var/log/caddy/your.domain
		format console
	}

	root * /var/www/wordpress
	encode gzip
	file_server
	php_fastcgi unix//run/php/php-fpm.sock

	@disallowed {
		path /xmlrpc.php
		path *.sql
		path /wp-content/uploads/*.php
	}

	rewrite @disallowed '/index.php'
}
  • For RHEL based systems .sock file should be /run/php-fpm/www.sock.

Replace your.domain 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 restart caddy.service
sudo systemctl enable caddy.service

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

systemctl status caddy

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

caddy setup wordpress ubuntu 18.04 min

Provider username and password.

There you go! You have successfully hosted your WordPress website using Caddy web server. For Nginx users, see Set up WordPress Multisite Network with Nginx and Let’s Encrypt 

Related Articles

Cloud Install OpenNebula KVM Node on Debian 12/11/10 Linux Mint How To Install Wine on Ubuntu or Linux Mint Debian How To Install and Use Solidity on Ubuntu / Debian Desktop Install PowerShell 7 on Ubuntu 24.04/22.04 and Debian 13/12

Press ESC to close