I’d wanted to try Caddy web server for a while and upgrading to the latest version of WordPress on my website broke the site. Something to do with their WP Super Cache but I couldn’t find anything via Google nor was opening a support ticket useful so I decided to replace it with a new server.
As its a low traffic site I can do it on one of Google’s smallest servers, again using an e2-micro configured with Ubuntu 24.04 Minimal.
Caddy installation is detailed here: https://caddyserver.com/docs/install#debian-ubuntu-raspbian
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
I then installed the stuff that I need that’s missing from Ubuntu Minimal:
sudo apt install bash-completion nano htop cron
I always change the history size in the shell so it keeps more, changing HISTSIZE=100000
HISTFILESIZE=20000:
nano .bashrc
With only 1GB ram, I always install zswap:
sudo nano /etc/default/grub.d/50-cloudimg-settings.cfg GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0,115200 zswap.enabled=1 zswap.compressor=zstd zswap.zpool=zsmalloc" sudo update-grub sudo fallocate -l 1G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo nano /etc/fstab /swapfile swap swap defaults 0 0 sudo crontab -e @reboot echo zstd > /sys/module/zswap/parameters/compressor
Use swapon or reboot to activate. For some reason the zswap compressor isn’t enabled at boot time, so the kludge in a crontab activates it.
It can be checked with:
grep -R . /sys/module/zswap/parameters
I normally configure swappiness which prevents kswapd kicking in and slowing everything down:
sudo nano /etc/sysctl.conf vm.swappiness = 1
I got the latest WordPress and installed it in the usual place:
wget https://wordpress.org/latest.tar.gz tar zxvf latest.tar.gz sudo mkdir -p /var/www/html sudo mv wordpress/ /var/www/html/ sudo chown -R www-data: /var/www/html/wordpress/
I then installed mysql and php:
sudo apt install mariadb-server php-apcu php-fpm php-mysql php-curl php-xml php-imagick php-mbstring php-zip php-gd php-intl
I then configured mysql:
sudo mysql_secure_installation sudo mysql CREATE USER "USER"@"localhost" IDENTIFIED BY "PASSWORD"; CREATE DATABASE xyze; GRANT ALL PRIVILEGES ON xyze.* TO "USER"@"localhost"; FLUSH PRIVILEGES;
This says that character set and collation are defaults so no need to specify explicitly: https://dev.mysql.com/doc/refman/8.0/en/charset-server.html
Caddy comes with a sample config: /etc/caddy/Caddyfile which will display a sample webpage when tested in the browser. Searching Google for a config brought up: https://caddy.community/t/setting-up-wordpress-with-caddy-on-ubuntu/18448 which I’ve altered slightly:
xyze.co.uk { redir https://www.xyze.co.uk } www.xyze.co.uk { # 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/xyze.co.uk format console } root * /var/www/html/wordpress encode zstd 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' }
Letsencrypt is configured by Caddy automatically so no Certbot configuration is necessary. I then set up WordPress via the browser using the mysql config from earlier.
I then dumped the previous db and loaded it into the new one:
mysqldump -uUSER -pPASSWORD xyze > /var/www/html/wordpress/sql/wp-backup.sql mysql -uUSER -pPASSWORD xyze < /var/www/html/wordpress/sql/wp-backup.sql
Logging into WordPress needed a db update and from there I configured the caching.
I’ve found that apcu is faster than Redis so have installed this one which needs the php-apcu I installed earlier:
https://wordpress.org/plugins/atec-cache-apcu/ This plugin gives opcache recommended settings: https://wordpress.org/plugins/atec-cache-info/ which are configured in:
sudo nano /etc/php/8.3/fpm/php.ini sudo systemctl restart php8.3-fpm caddy
Unfortunately their page cache seems buggy and they’ve superseded it in one of their other plugins, so I’m using https://wordpress.org/plugins/powered-cache/ which I’ve used successfully before. The other plugin needed is the Cloudflare one which will update Cloudflare when a new post is made: https://wordpress.org/plugins/cloudflare/
I like to backup the db every night to make it ready for the external rsync backup:
sudo crontab -l # m h dom mon dow command @reboot echo zstd > /sys/module/zswap/parameters/compressor 35 0 * * * /usr/bin/mysqldump -uUSER -pPASSWORD xyze > /var/www/html/wordpress/sql/wp-backup.sql