I shared how to install WordPress running on Caddy Server in the previous article: Install WordPress running on Caddy Server using Docker Compose. This method is suitable for those who have already set up Caddy, and want to use Caddy as a reverse proxy for a new WordPress site.
This article will introduce about WordPress-Caddy-Docker – The repo I set up on Github helps simplify setting up a WordPress website running on Caddy Server.
Advantages of WordPress-Caddy-Docker:
- Install WordPress running on Caddy quickly in 1 minute
- Built-in feature to install additional plugins and default themes.
- WP-CLI integration to manage WordPress using command line.
- Plugin compatibility Cache Enabler.
Compared to the ols-docker-env combo shared, this new wordpress-caddy-docker combo makes installing WordPress much simpler and faster.
I. Download WordPress-Caddy-Docker
Clone repo WordPress-Caddy-Docker from Github to your server
cd /home
git clone https://github.com/10h30/wordpress-caddy-docker
Code language: Bash (bash)
Go to wordpress-caddy-docker folder
cd ./wordpress-caddy-docker
Code language: Bash (bash)
The initial directory structure will be as below
.
|-- caddy
| `-- Caddyfile
|-- compose.yml
|-- .env
|-- LICENSE
|-- README.md
|-- wordpress
| `-- custom.ini
|-- wp-init.sh
|-- wp-install.sh
`-- wp-uninstall.sh
Code language: JavaScript (javascript)
II. Configure .env parameters
You need to change the parameters in the .env file to suit your needs. The default Content is as below:
## Caddy ##
SERVER_NAME = 10h30.net
## WordPress ##
WORDPRESS_DB_USER=siteuser
WORDPRESS_DB_PASSWORD=sitepassword
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_HOST=db:3306
WORDPRESS_CONFIG_EXTRA=define('WP_REDIS_HOST','redis');
# Website Credentials
WORDPRESS_ADMIN_USER = admin
WORDPRESS_ADMIN_PASSWORD = youradminpassword
WORDPRESS_ADMIN_EMAIL = admin@domain.com
# Blog Settings
WORDPRESS_TITLE = 'Blog Title Here'
WORDPRESS_PERMALINK_STRUCTURE = /%postname%/
WORDPRESS_THEME_TO_INSTALL = "kadence"
WORDPRESS_PLUGINS_TO_INSTALL = "redis-cache cache-enabler seo-by-rank-math"
## MYSQL ##
MYSQL_USER=siteuser
MYSQL_PASSWORD=sitepassword
MYSQL_DATABASE=wordpress
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_RANDOM_ROOT_PASSWORD=1
MARIADB_RANDOM_ROOT_PASSWORD=1
Code language: Nginx (nginx)
Required fields to change
- Line 2 – SERVER_NAME: change to the domain name you want to install WordPress
- Line 12-14 – # Website Credentials: change username / password / Email of admin account
III. Install WordPress
Grant execution permission to existing .sh files
find . -type f -iname "*.sh" -exec chmod +x {} ;
Code language: Bash (bash)
Activate the system
./wp-install.sh
Wait a few seconds for Docker Compose to initialize the necessary containers. You can then access the domain name you set up in step III to install WordPress.
However, you can install it automatically from the command line using the file wp-init.sh
This file will automatically configure WordPress and install additional plugins and themes that have been configured in the file. .env
in step III
./wp-init.sh
During the installation process, the system will ask if you want to install additional plugins and themes:
Do you want to install recommended plugins? (Y/n)
By default, 3 plugins will be installed: Redis Cache, Cache Enabler and Rank Math.Do you want to install recommended theme? (Y/n)
. By default, Kadence theme will be installed.
The installation process takes about 1-2 minutes. After installation is complete, you will see a report as below.
REPORT
== User List ==
(+) Creating 2/0
Container wordpress-caddy-docker-db-1 Running 0.0s
Container wordpress Running 0.0s
+----+------------+--------------+------------------+---------------------+---------------+
| ID | user_login | display_name | user_email | user_registered | roles |
+----+------------+--------------+------------------+---------------------+---------------+
| 1 | admin | admin | admin@domain.com | 2024-07-08 10:51:12 | administrator |
+----+------------+--------------+------------------+---------------------+---------------+
== Theme List ==
(+) Creating 2/0
Container wordpress-caddy-docker-db-1 Running 0.0s
Container wordpress Running 0.0s
+-------------------+----------+--------+---------+----------------+-------------+
| name | status | update | version | update_version | auto_update |
+-------------------+----------+--------+---------+----------------+-------------+
| kadence | active | none | 1.2.6 | | off |
| twentytwentyfour | inactive | none | 1.1 | | off |
| twentytwentythree | inactive | none | 1.4 | | off |
| twentytwentytwo | inactive | none | 1.7 | | off |
+-------------------+----------+--------+---------+----------------+-------------+
== Plugin List ==
(+) Creating 2/0
Container wordpress-caddy-docker-db-1 Running 0.0s
Container wordpress Running 0.0s
+--------------------+----------+--------+---------+----------------+-------------+
| name | status | update | version | update_version | auto_update |
+--------------------+----------+--------+---------+----------------+-------------+
| akismet | inactive | none | 5.3.2 | | off |
| cache-enabler | active | none | 1.8.15 | | off |
| hello | inactive | none | 1.7.2 | | off |
| seo-by-rank-math | active | none | 1.0.222 | | off |
| redis-cache | active | none | 2.5.2 | | off |
| advanced-cache.php | dropin | none | | | off |
+--------------------+----------+--------+---------+----------------+-------------+
Code language: Nginx (nginx)
The website has been successfully installed, activated using the Kadence theme and pre-configured with the Cache Enabler plugin for speed optimization.
Let’s Encrypt SSL certificate for the domain is automatically configured by Caddy so you don’t need to do anything more to configure https for the website.
If you want to delete the website you just created, you activate the file
./wp-uninstall.sh
then reinstall from the beginning from step III.
IV. Advanced PHP configuration
You can configure advanced PHP parameters by editing the custom.ini file.
nano wordpress/custom.ini
Code language: Nginx (nginx)
Then restart the system with the command
docker compose restart
Code language: Nginx (nginx)
V. Manage WordPress with WP-CLI
I have also integrated the WP-CLI tool in this combo so you can quickly manage WordPress using the command line.
For example, view system information with the following command
docker compose run wpcli
Code language: Dockerfile (dockerfile)
Results returned
OS: Linux 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64
Shell:
PHP binary: /usr/local/bin/php
PHP version: 8.2.21
php.ini used:
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 15.1 Distrib 10.11.8-MariaDB, for Linux (x86_64) using readline 5.1
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /var/www/html
WP-CLI packages dir:
WP-CLI cache dir: /home/www-data/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.10.0
Code language: YAML (yaml)
Install additional plugins using the following command (install Fluent Form plugin)
docker compose run wpcli plugin install fluentform
Code language: Dockerfile (dockerfile)
Activate the newly installed plugin
docker compose run wpcli plugin activate fluentform
Code language: Dockerfile (dockerfile)
Backup database with following command
docker compose run wpcli db export --add-drop-table
Code language: Dockerfile (dockerfile)
The sql file will be saved in the folder wordpress/html
VI. Performance Evaluation
I have moved this MarkKnow.com blog to run on Caddy platform since May 2024. Before that, the blog ran on OpenLiteSpeed platform, and before that, Nginx.
I don’t have time to directly compare the performance of WordPress on Caddy vs OpenLiteSpeed (OLS) vs Nginx. I switched to Caddy initially for testing, and found it worked so well that I’ve been using it ever since.
Advantages of using Caddy over OLS and Nginx:
- Automatically set up Let’s Encrypt SSL certificate for domain name. No need to install and configure anything complicated like when using Nginx or OLS
- Quick and easy installation (when using repo) WordPress-Caddy-Docker I have pre-configured). It only takes less than 5 minutes for the website to be ready.
- Combine with Cache Enabler plugin (free) to create cache, improve website loading speed. This plugin is simpler and easier to use than LiteSpeed Cache plugin.
The instructions in this article only apply when you only install 1 website on the server. If you want to install multiple websites, you need to customize the directory structure and reconfigure the files. compose.yml
and Caddyfile
be suitable.
I am setting up 2 websites: this blog MarkKnow.com and blog MarkGame.net on the same server, and configure the directory as below
├── caddy
│ ├── Caddyfile
│ ├── caddy_config
│ ├── caddy_data
│ └── compose.yml
├── markknow.com
│ ├── compose.yml
│ ├── conf
│ ├── dbdata
│ └── html
└── markgame.net
├── compose.yml
├── conf
├── dbdata
└── html
Code language: CSS (css)
When I have time, I will guide you how to configure Caddy as a server for multiple WordPress websites on the same server.
Good luck with your installation!
If my article provides useful information and knowledge to you, don’t hesitate to invite me for a beer to have more motivation to share more. Thank you!
Comment Policy: We truly value your comments and appreciate the time you take to share your thoughts and feedback with us.
Note: Comments that are identified as spam or purely promotional will be removed.
To enhance your commenting experience, consider creating a Gravatar account. By adding an avatar and using the same e-mail here, your comments will feature a unique and recognizable avatar, making it easier for other members to identify you.
Please use a valid e-mail address so you can receive notifications when your comments receive replies.