Skip to content

FrankenPHP Configuration

FrankenPHP adds PHP interpolation to web sites served by its underlying Caddy web server. In this example we’ll create two documentation subdomainds, zen-php.langley.stream and pond-7-docs.langley.stream, which will serve static Zensical documentation sites with PHP interpolation enabled.

Caddy server

Edit the Caddy web server configuration

bash
nano /etc/frankenphp/Caddyfile

Caddy configuration for serving static Zensical documentation sites

/etc/frankenphp/Caddyfile
### Begin zen-php.langley.stream configuration ###
zen-php.langley.stream {
        root /opt/zensical/zensical-project/site

        # 09/12/26: Serve both .php and .html files as php code:
        # See: https://caddyserver.com/docs/caddyfile/matchers#path
        @phpFiles {
                path *.html *.php
        }

        php @phpFiles
        encode
        php_server
}
### End zen-php.langley.stream configuration ###

### Begin pond-7-docs.langley.stream configuration ###
pond-7-docs.langley.stream {
        root /opt/zensical/pond-7-project/site

        # 09/12/26: Serve both .php and .html files as php code:
        # See: https://caddyserver.com/docs/caddyfile/matchers#path
        @phpFiles {
                path *.html *.php
        }

        php @phpFiles
        encode
        php_server
}
### End pond-7-docs.langley.stream configuration ###

Run the project inside web space

The folders for Docker compose projects are often placed under /root, however HTML files usually cannot be served from inside root’s home directory. Rather than copying Zensical’s generated static site folder to a web-accessible directory we can relocate the entire Docker Zensical project into web-accessible space in /opt:

    /opt/<project-name>
  1. Move Zensical’s Docker compose folder (containing docker-compose.yml) into /opt:
    bash
    mv /path/to/your/project /opt/my-project
    
  2. Assign directory permissions compatible with the web server user and group (www-data on Debian-based Linux):

    bash
    chown -R $USER:www-data /opt/my-project
    chmod -R 755 /opt/my-project
    

  3. Start the Zensical project container:

    bash
    cd /opt/my-project
    docker compose up -d