PHP code interpolation¶
PHP Test Code¶
The following code snippet is a simple test to verify whether PHP code interpolation is working correctly, in which case the current date and time will be displayed below the code snippet.
<?php
// Set the default timezone
date_default_timezone_set( 'America/Los_Angeles' );
echo date( 'l, F j, Y, ' ) . date( 'h:i:s a' );
echo "<br>Page last updated: " . date( 'F d, Y, h:i:s a.', filemtime( __FILE__ ) );
echo "<br>Path: " . __FILE__;
?>
Page last updated: October 24, 2026, 11:44:55 am.
Path: /opt/zensical/pond-7-project/site/php-test.html
Is the current date and time shown immediately above?
Setting up PHP interpolation¶
Our Zensical subdomains are served by FrankenPHP, which adds fast PHP code interpolation to its underlying Caddy web server. Zensical runs its own web server on a separate localhost port which can be reverse-proxied to the internet:
https://zen.langley.stream:4443/
Unfortunately FrankenPHP offers no easy way to execute any PHP code flowing from a reverse-proxied backend server,
it needs to directly access the static HTML files built by Zensical, located in the project's site directory.
Copy Zensical's site directory into our web root:
Note
If the destination folder already exists and you want to copy the contents of the source directory directly into it without nesting folders, append /. to the source path.
Our https://zensical.langley.stream:4443/ subdomain directly serves the static Zensical files, without reverse proxy, and is therefore able to interpolate embedded PHP code.
FrankenPHP configuration¶
### Begin zen-proxy.langley.stream configuration ###
zen-proxy.langley.stream {
# Reverse proxy the Zensical server running on localhost port 8006:
reverse_proxy localhost:8006
}
### End zen-proxy.langley.stream configuration ###
### Begin zen-php.langley.stream configuration ###
zen-php.langley.stream {
root /var/www/zensical/site-copy
# 09/12/26: Serve both php and html files as php:
# See: https://caddyserver.com/docs/caddyfile/matchers#path
@phpFiles {
path *.html *.php
}
php @phpFiles
encode
php_server
}
### End zen-php.langley.stream configuration ###
Run the project inside /var/www¶
Rather than copying the site folder from its location outside our web directory
we can relocate the entire Docker project directory into web-accessible space.
- Move your project folder into
/var/www: - Assign directory permissions:
cp -ru /root/docker/zensical /var/www/z
chown -R $USER:www-data /var/www/z
chmod -R 755 /var/www/z
cd /var/www/z/zensical
docker compose up -d
Adjust directory structure¶
The use_directory_urls setting in zensical.tomlcontrols the directory structure of your documentation site,
and thereby the URL format used for linking to pages. Turn it off to generate file-based URLs, facilitate offline
usage, and enable interpolation of .html files with embedded PHP code.
Note that this is automatically set to false when building for offline usage,
so your documentation can be browsed from a local filesystem without a web server. The default value is true.
Add modification date to footer¶
Add the page modification date in the footer's copyright notice: