How to Set Up a WordPress Site with Caddy and FrankenPHP

On
Coding in a laptop

Generally, while setting up a WordPress instance, we use the LAMP stack which is a kind of defacto standard for serving PHP websites. But, a modern software stack is available that's secure, easy to manage, and blazingly fast with loads of built-in useful features. A combination of Caddy and FrankenPHP makes a world-class stack to serve PHP-powered websites. It doesn't require any external caching module and configures HTTPS automatically. In this tutorial, we'll learn to set up this modern software stack on a VPS server to help you install a fresh WordPress site in a few easy steps. Let's get started!

Coding in a laptop
📷 Credit: fullvector / Freepik

The configuration as well as adding and removing features on this new stack is comparatively easier. All you need to know is the availability of the feature and the basic syntax for the config file.

Read Also:
Step-by-Step Guide: WordPress Installation with Let's Encrypt SSL on VPS

Caddy can also be used on a computer with support for HTTPS for local URLs to develop websites before transferring them to the actual server. So, get ready to master the setup of this new stack.

Prerequisites for the Setup

Before we dive into the actual process, let's quickly take a look at the resources and tools required to complete this job. Here's a checklist for the same:

  • A Linux VPS or dedicated server with Ubuntu 22.04+ preinstalled on it.
  • Access to root credentials.
  • A registered domain name for the WordPress site.
  • Working knowledge of the Linux command line environment.

This setup will not work on a shared web server as it does not give you enough privileges to install a different software stack other than the one installed on it, by default.

Step 1: Update Your Linux System

Start with updating your Linux system to grab the latest packages and libraries. Here's how to do it.

sudo apt update && sudo apt upgrade -y

Next, we need some packages required to complete the installation and setup process.

sudo apt install curl git unzip -y

If you already have these packages on your system, you can skip this step.

Step 2: Point Your Domain to the Server

The next step is to make sure your domain name is pointing to your Linux server. To do that grab the IP address assigned to your server and access the domain's control panel to add an A record for the same.

Its format is generally like this:

(Type) A Record | (Host) @ | (Value) xxx.xxx.xxx.xxx

Here, @ denotes the root domain, and xxx.xxx.xxx.xxx should be replaced with the IP address of your server. After adding this DNS record, wait for at least 30 minutes before starting the installation process.

Step 3: Install Caddy

It's time to install Caddy on our Linux server. To do that, we have to grab the latest stable version of the same. Here are the installation steps.

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
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

# Verify if Caddy is installed successfully:
caddy version

It shouldn't take much time to complete Caddy server's installation process. Let's move on to the next step.

Step 4: Install FrankenPHP

It's time to install FrankenPHP PHP server that's written in Go and has a builtin caching mechanism eliminating the need to install PHP-FPM as a separate module. Here's how to install it:

cd /usr/local/bin
sudo curl -LO https://github.com/dunglas/frankenphp/releases/latest/download/frankenphp-linux-amd64
sudo chmod +x frankenphp-linux-amd64
sudo mv frankenphp-linux-amd64 frankenphp

# Confirm installation:
frankenphp -v

We have directly fetched the standalone binary from GitHub and have configured it in the respective directory for systemwide availability.

Step 5: Create a Directory for Your WordPress Site

Let's create a directory for the website where all the WordPress files will reside.

sudo mkdir -p /var/www/wordpress
cd /var/www/wordpress

Although it's a best practice to name this directory wp or wordpress, feel free to use your preferred name if you intend to do so.

Step 6: Download and Set Up WordPress

Finally, it's time to download WordPress and do its preliminary configuration. Follow these steps to complete this process.

curl -O https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/* .
rm -rf wordpress latest.zip

After file extraction, let's quickly apply the necessary permissions to secure our installation.

sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;

If you have given a different name to the directory, make the necessary changes in the commands.

Step 7: Set Up a MySQL or MariaDB Database

The next step is all about installing and configuring the database management system for our WordPress instance. One can either use MySQL or MariaDB for this purpose.

We'll use the latter one in this case. Here we go!

Install MariaDB Server

sudo apt install mariadb-server -y

Run Secure Installation

Execute the MariaDB security script and follow the prompts to complete the security hardening of the database instance.

sudo mysql_secure_installation

Create a WordPress Database

sudo mysql -u root -p

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Make sure to replace strongpassword with an actual strong and secure password.

Step 8: Configure Caddy with FrankenPHP

To run PHP, we'll configure Caddy with FrankenPHP. It's a simple process involving the creation and editing of Caddyfile from where all the config and settings are read and processed.

First, create and open the file.

sudo nano /etc/caddy/Caddyfile

Now add the following directives and rules in this file:

your-domain.com {
    root * /var/www/wordpress
    php {
        frankenphp /usr/local/bin/frankenphp
    }
    encode gzip
    file_server
    try_files {path} /index.php?{query}
    log {
        output file /var/log/caddy/access.log
    }
}

Do not forget to replace your-domain.com with the actual domain you are going to use for your WordPress site.

Step 9: Restart Caddy

After completing the initial configuration, it's time to restart the Caddy server.

sudo systemctl restart caddy

Upon restart, Caddy will automatically configure the Let's Encrypt SSL certificate for your domain name.

Step 10: Complete WordPress Setup via Browser

The last step is dead simple. Open your website https://your-domain.com in a web browser and complete the WordPress installation wizard. You have to fill in the same database information in this wizard you have used while creating the MariaDB database in one of the earlier sections.

Conclusion

Congratulations! You’ve just deployed a production-ready WordPress site using the Caddy web server and FrankenPHP—a modern, lean, and high-performance PHP engine that simplifies WordPress hosting by many folds.

Why this modern stack is better than the old ones?

  • Auto HTTPS with Caddy
  • No need to install PHP-FPM
  • Modern Go-powered performance
  • Simple configuration and easy-to-maintain

Try it now and let me know how it goes on your server!