Running on a Mac

On this page

Install

curl -fsSL https://photon-http.sstools.co/install.sh | bash

The installer clones the repository, builds a release photon with your Swift toolchain (as you) and installs it to /usr/local/bin/photon, which is on every Mac's default PATH. Only the final copy uses sudo, and only when /usr/local/bin is not writable; it says so and asks for your password. It never edits your shell files. Options (after bash -s --):

OptionMeaning
--prefix DIRInstall to DIR/bin instead of /usr/local/bin; a writable DIR (e.g. ~/.local) needs no sudo. If DIR/bin is not on your PATH, the installer prints the export line to add
--version REFGit tag or branch to build (default main)

From a checkout, scripts/install.sh builds and installs that checkout. Run the installer again to update. Uninstall with sudo rm /usr/local/bin/photon.

Requirements: macOS 15 or later and a Swift 6.4 toolchain (Xcode or swift.org).

Build by hand

swift build -c release -j 2 --product photon     # or scripts/build.sh
.build/release/photon --help

The binary has no dependencies outside the system, so you can copy .build/release/photon anywhere, e.g. /usr/local/bin or ~/bin.

Serve a folder

cd ~/Sites/my-site
photon serve                        # http://127.0.0.1:8080/
photon serve ~/Sites/blog --port 9000
photon serve [DIR] [--port PORT] [--host HOST]

photon serve serves DIR (default: the current directory) as a static website. A request for / or any directory serves its index.html; a directory requested without the trailing slash redirects to it. --port defaults to 8080 (0 picks a free one) and --host to 127.0.0.1, so only this Mac can connect; --host 0.0.0.0 shares the site with your network (see the firewall prompt). It prints listening HOST:PORT once ready; Ctrl-C stops.

serve never reads http-config.json, so a stray config file cannot change what it does. For HTTPS, compression, access logs, error pages or virtual hosts, write a config and run photon --config FILE (below).

Command line

photon [--config FILE] [--root DIR] [--host HOST] [--port PORT]
FlagMeaning
--config FILEThe JSON config. Without it: $ROOT_PATH/http-config.json when ROOT_PATH is set, else ./http-config.json if it exists, else built-in defaults
--root DIRDirectory to serve; overrides root. Relative to the working directory
--host HOSTNumeric address to bind; overrides host
--port PORTCleartext port; overrides port. 0 picks a free one
--help, -hUsage

--flag=value works too. Output:

Exit status: 0 after a graceful stop, 1 on a configuration or startup error (bad value, missing root, unreadable identity, port in use) with a message naming the key, 2 on a usage error.

Control commands

The same executable checks a config and talks to a running server (#0143). It finds the server through its status file (statusFile, default run/status.json next to the config) and signals its pid; there is no control socket, so nothing new is reachable over the network.

photon check   [--config FILE] [--root DIR] [--host HOST] [--port PORT]
photon reload  [--config FILE] [--root DIR] [--host HOST] [--port PORT] [--timeout SECONDS]
photon status  [--config FILE] [--json]
photon restart [--config FILE] [--root DIR] [--host HOST] [--port PORT] [--timeout SECONDS]
photon cert status [--config FILE] [--json]
photon cert renew  [--force] [--config FILE] [--timeout SECONDS]
CommandWhat it does
checkLoads and builds the config as a reload would (root, error pages, credential files, the TLS identity in memory only) and prints PATH: valid or PATH: invalid: …. When a server runs with this config, it also prints which keys would change: can hot-reload: root changed, no setting changes (a reload still rereads the identity and credential files), or needs a restart: port changed and needs a restart; runphoton restartto apply them
reloadRuns check; when the config is valid and needs no restart, sends SIGHUP and waits (up to --timeout, default 10 s) for the server to record the outcome, then prints reloaded: …, reload failed, … or reload rejected, …. It does not signal when the config is invalid or needs a restart
statusPrints the status file: state and pid, listening addresses, config path and SHA-256, the last reload (time, signal or watch, result, message), the reload count and any restart-required keys. --json prints the file itself
cert status, cert renewThe tls.acme certificate: show it, or ask the server to renew it (SIGUSR1). See Let's Encrypt certificates
restartRuns check; when the config is valid (whether or not it needs a restart), sends SIGUSR2 and waits (up to --timeout, default 10 s) for the outcome: restarted (changed: port); listening … or restart failed, the running server keeps serving: …. The graceful restart happens in the same process, so launchd sees one pid. It does not signal when the config is invalid

Without --root/--host/--port, check, reload and restart apply the overrides the running server was started with (recorded in the status file). Exit status: 0 success, 1 invalid config, no running server, a failed reload or restart, or a timeout, 2 usage error, 3 a restart is required (the reload was or would be rejected).

The status file is JSON, rewritten atomically (temporary file, then rename) with mode 0600 at startup once the listeners are bound, after every reload and restart and at a clean exit ("state": "stopped"). It holds pid, started, config, configSHA256 (of the file as last loaded), arguments, listening, reloads (reloads and restarts), lastReload (time, trigger: signal / watch / restart, result: reloaded / failed / rejected / restarted, message, changed, restartRequired), restarted (time of the last graceful restart), restartRequired (keys changed in the file but not applied; empty after a successful reload or restart), with tls.acme also certificate (names, issuer, serial, validity, next renewal, last error), certificateRequests and lastCertificateRequest (#0152), and settings: a digest per key of the running values, never the values themselves, so check can compare without the file holding passwords. It is written only when the server runs with a config file.

http-config.json reference

The file is one JSON object. Every key is optional: a missing key keeps its default, so {} (or no file) is a valid config serving ./Public on 127.0.0.1:8080. Unknown keys print a warning and are ignored. A wrong type or out-of-range value stops the server (exit 1) with a message such as "timeouts.idle" must be a number of seconds. Relative paths resolve against the directory holding the config file (except --root).

Durations are numbers of seconds (fractions allowed, at most one year). For the HTTP/1.1 timeouts and the proxy's proxy[].timeouts (connect, response, idle, total), 0 or null turns a limit off; leaving a key out keeps its default. Turn off the proxy's idle and response limits (or set them large) for long-polling or streaming upstreams such as server-sent events.

Root/http-config.json spells out the core defaults; Root/http-config.tls.json adds HTTPS and HTTP/3; Root/http-config.proxy.json adds a reverse-proxy mount.

Listening and limits

KeyTypeDefaultMeaning
hoststring"127.0.0.1"Numeric address to bind. "0.0.0.0" (IPv4) or "::" serves the network
portinteger 0–655358080Cleartext TCP port; 0 picks one
transport"bsd" | "nw""bsd"Cleartext transport: POSIX sockets + kqueue, or Network.framework
maxConnectionsinteger ≥ 11024Connections served at once across all listeners; more wait in the listen backlog
maxBodySizeinteger bytes10485760Largest request body (413 above). Legacy alias maxRequestSize
timeoutsobjectsee belowHTTP/1.1 time limits in seconds
timeouts.headerseconds10Request head must complete (408)
timeouts.idleseconds5Idle keep-alive connection closed; also an idle HTTP/2 connection (GOAWAY). Legacy keepAliveTimeout
timeouts.bodyseconds30Longest wait for request body bytes (408)
timeouts.sendseconds30Longest wait for the client to accept response bytes
timeouts.lingerseconds2Lingering close after an error response
drainTimeoutseconds or null10Graceful stop waits this long for open connections; null waits indefinitely (0 cancels at once)
reloadbool or object{"watch": true, "interval": 2}Hot reload when the config or a file it names changes (reload). false reloads on SIGHUP only
reload.watchbooltruePoll the files with stat and reload on a change
reload.intervalseconds 0.01–36002Time between polls
statusFilepath, false or null"run/status.json"Status file for the control commands, relative to the config's directory; false turns it off

Files

KeyTypeDefaultMeaning
rootstring"Public"Directory to serve. Legacy alias path
indexstring or array["index.html"]Index files tried in order for a directory. Legacy alias defaultIndex
mimeTypesobject{}Extra or overriding types: {"md": "text/markdown; charset=utf-8"}. The legacy array form [{"contentType": …, "pathExtensions": […]}] is accepted
defaultMimeTypestring"application/octet-stream"For unknown extensions
blockListarray of strings["http-config.json", ".git", ".DS_Store"]Path components answered 403 anywhere in the path, case-insensitively
blockDotfilesbooltrue403 for any component starting with ., except .well-known
cachingbool or object{"enabled": true, "maxAge": 3600}Cache-Control: public, max-age=N on files and 304s; false or "enabled": false sends none
errorPagesbool or objecttruetrue: generated HTML pages for bodiless 4xx/5xx; false: none; {"404": "errors/404.html"}: files relative to root (other statuses keep the generated page); with hosts, each site's root first, then root
compressionbool or objectoffSee Compression
enableETags––Legacy, no effect (ETags are always sent); accepted with a warning
enableCompressionbool–Legacy; true is "compression": true (ignored when compression is set)

Compression

"compression": true uses every default, or an object:

KeyTypeDefaultMeaning
enabledbooltruefalse turns it off
encodingsarray["br", "gzip", "deflate"]Codings offered, from br, gzip, deflate
minimumSizeinteger bytes1024Smaller bodies are sent as they are
levelinteger 1–94zlib level for per-response gzip/deflate
precompressionLevelinteger 1–99Level for static-file variants compressed once into the cache
mimeTypesarraytext/*, JSON, JavaScript, XML (incl. SVG), wasm, YAML, TOML, some fonts and iconsTypes that are compressed; * wildcards allowed
precompressbooltrueCompress small static files once into the file cache
sidecarsbooltrueServe file.br / file.gz next to a file as its variants

TLS, HTTP/2 and HTTP/3

KeyTypeDefaultMeaning
tlsobject, false or nulloffHTTPS listener
tls.identitystring (required)–PKCS#12 file (certificate chain + key), relative to the config file. Loaded in memory only
tls.passwordstring–Its password; or
tls.passwordEnvstring–Name of an environment variable holding the password (exactly one of the two)
tls.portinteger8443TCP port; must differ from port; 0 picks one
tls.enabledbooltruefalse turns it off
tls.acmeobject–Instead of identity: the server gets and renews a Let's Encrypt certificate itself. Keys email, domains, directory, agreeToTerms, stateDirectory, profile, redirectHTTP, startup, externalAccountBinding, caCertificates: reference
http2bool or objectonHTTP/2. On by default (offered on HTTPS via ALPN); false or "enabled": false serves HTTP/1.1 only
http2.cleartextboolfalseAlso accept h2c with prior knowledge on the cleartext port (every cleartext connection is then sniffed)
http2.maxConcurrentStreamsinteger 0–65536100SETTINGS_MAX_CONCURRENT_STREAMS
http2.initialWindowSizeinteger 0–214748364765535Per-stream receive window
http2.maxRequestBodySizeinteger or nullmaxBodySizeLargest request body on HTTP/2
http2.abuseLimitsobjectdefaultsDoS limits (counts per window; null turns one off): window (s, 10), maxResetStreamsPerWindow (100), maxControlFramesPerWindow (1000), maxEmptyFramesPerWindow (100), maxWindowUpdatesPerWindow (10000), maxSmallDataFramesPerWindow (1000), smallDataFrameSize (256), windowStallTimeout (s, 30), maxStreamsPerConnection (100000). Background: HTTP2.md
http3bool or objectoffHTTP/3 over QUIC; needs tls. true = defaults
http3.portinteger or nullTLS port numberUDP port (the same number as HTTPS is normal: TCP and UDP do not clash)
http3.altSvcMaxAgeinteger seconds86400ma of the Alt-Svc header on HTTPS responses
http3.qpackMaxTableCapacityinteger 0–10485760QPACK dynamic table offered to clients; 0 = static table only
http3.qpackBlockedStreamsinteger 0–10000Streams that may wait on QPACK inserts
http3.enabledbooltruefalse turns it off

Virtual hosts, auth, proxy and logs

These have their own sections:

KeyDefaultReference
hosts[]Virtual hosts
auth[]Authentication
proxy[]Reverse proxy reference
accessLogoffLogs below

HTTPS with a PKCS#12 identity

For a certificate the server obtains and renews by itself, use tls.acme instead: see Let's Encrypt certificates. This section is about a .p12 file you provide.

The server loads a PKCS#12 (.p12) file holding the certificate chain and private key, in memory only (SecPKCS12Import with kSecImportToMemoryOnly). It never touches the keychain, so nothing prompts and nothing is installed.

{
  "host": "0.0.0.0",
  "port": 80,
  "root": "/Users/me/Sites/example",
  "tls": { "identity": "certs/example.p12", "passwordEnv": "SWS_P12_PASSWORD", "port": 443 },
  "http3": true
}

Local testing

scripts/make-test-identity.sh            # .test-identity/server.p12, self-signed for localhost
.build/release/photon --config Root/http-config.tls.json
curl -k https://127.0.0.1:8443/                      # HTTP/2 via ALPN
curl -k --http1.1 https://127.0.0.1:8443/
/opt/homebrew/opt/curl/bin/curl --http3-only -k https://127.0.0.1:8443/   # Homebrew curl has HTTP/3

Browsers reject a self-signed certificate unless you trust it, which changes the keychain's trust settings; do that by hand only if you want to, or test with curl.

A real certificate (Let's Encrypt)

The simplest way is the built-in client: a tls.acme block, no files to convert (Let's Encrypt certificates). Use an external client as below when you need DNS-01 or wildcards, when port 80 isn't reachable, or when the certificate is shared (When to use certbot instead).

Any ACME client that writes PEM files works, for example certbot, lego or acme.sh (all installable with Homebrew). The HTTP-01 challenge needs the domain to reach this Mac on port 80, and StaticFiles serves /.well-known/ even with blockDotfiles on, so you can use webroot mode with your site's root.

The server wants a PKCS#12 file, so every renewal ends with the same step: convert the PEM chain and key, put the new .p12 over the old one, reload. scripts/acme-deploy-hook.sh does that step and works unchanged as a certbot deploy hook, a lego run/renew hook, an acme.sh --reloadcmd, or by hand. Copy it somewhere stable, outside ~/Desktop, ~/Documents and ~/Downloads:

mkdir -p ~/letsencrypt
curl -fsSL -o ~/letsencrypt/acme-deploy-hook.sh \
  https://raw.githubusercontent.com/brennanMKE/PhotonHTTP/main/scripts/acme-deploy-hook.sh
chmod 755 ~/letsencrypt/acme-deploy-hook.sh

What it does, in order (the exit status names the step that failed):

  1. Reads the PEM full chain and key: --cert/--key, else certbot's RENEWED_LINEAGE (fullchain.pem, privkey.pem), else lego's LEGO_CERT_PATH/LEGO_CERT_KEY_PATH, else acme.sh's CERT_FULLCHAIN_PATH/CERT_KEY_PATH (exit 2 when there are none, 3 when a file is missing).
  2. Takes the password from the environment only: --password-env NAME, else the config's tls.passwordEnv, else SWS_P12_PASSWORD (exit 4 when it is not set).
  3. Converts with -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1, using Homebrew's OpenSSL when installed (exit 5 no openssl, 6 conversion failed, e.g. the key does not match).
  4. Writes a temporary file in the destination folder, checks that it decrypts and holds the input's leaf certificate (exit 7), chmod 600, then mvs it over --out (default: the config's tls.identity; exit 8). A bad bundle never replaces a good one.
  5. Runs photon reload --config FILE (exit 9 if it fails). With the file watcher on (reload.watch, the default) it skips this: the server sees the new file within reload.interval. --reload always reloads anyway, --reload never never; without --config it only installs the file.

It only runs openssl on files and signals the server: no keychain, no sudo. acme-deploy-hook.sh --help lists every option.

certbot

Homebrew's certbot defaults to /etc/letsencrypt, which needs root. Give it three folders of your own instead and nothing needs sudo; pass the same three options to every certbot command, including renew:

brew install certbot
export SWS_P12_PASSWORD='a long random password'   # the server reads it too (tls.passwordEnv)
certbot certonly --webroot -w /Users/me/Sites/example \
  -d example.com -d www.example.com -m you@example.com --agree-tos --non-interactive \
  --config-dir ~/letsencrypt/config --work-dir ~/letsencrypt/work --logs-dir ~/letsencrypt/logs \
  --deploy-hook "$HOME/letsencrypt/acme-deploy-hook.sh --config /Users/me/Sites/example/http-config.json"
# PEMs: ~/letsencrypt/config/live/example.com/{fullchain,privkey}.pem
# the hook wrote the config's tls.identity (certs/example.p12) and reloaded the server

-w is the folder the server serves (its root), so the challenge file certbot writes under .well-known/acme-challenge/ is reachable on port 80. certbot runs the deploy hook after the first certificate and stores it in ~/letsencrypt/config/renewal/example.com.conf, so every later certbot renew runs it again.

macOS has no certbot timer. A LaunchAgent runs certbot renew twice a day (it renews only certificates within 30 days of expiry, so most runs do nothing). Save as ~/Library/LaunchAgents/com.example.certbot-renew.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.example.certbot-renew</string>
  <key>ProgramArguments</key>
  <array>
    <string>/opt/homebrew/bin/certbot</string>
    <string>renew</string>
    <string>--quiet</string>
    <string>--config-dir</string>
    <string>/Users/me/letsencrypt/config</string>
    <string>--work-dir</string>
    <string>/Users/me/letsencrypt/work</string>
    <string>--logs-dir</string>
    <string>/Users/me/letsencrypt/logs</string>
  </array>
  <key>EnvironmentVariables</key>
  <dict>
    <!-- the hook needs photon and openssl on PATH, and the .p12 password -->
    <key>PATH</key>
    <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
    <key>SWS_P12_PASSWORD</key>
    <string>…</string>
  </dict>
  <key>StartCalendarInterval</key>
  <array>
    <dict><key>Hour</key><integer>3</integer><key>Minute</key><integer>17</integer></dict>
    <dict><key>Hour</key><integer>15</integer><key>Minute</key><integer>17</integer></dict>
  </array>
  <key>StandardOutPath</key>
  <string>/Users/me/letsencrypt/logs/renew.out.log</string>
  <key>StandardErrorPath</key>
  <string>/Users/me/letsencrypt/logs/renew.err.log</string>
</dict>
</plist>
chmod 600 ~/Library/LaunchAgents/com.example.certbot-renew.plist   # it holds the password
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.certbot-renew.plist
launchctl kickstart gui/$(id -u)/com.example.certbot-renew          # one run now, to check
certbot renew --dry-run --config-dir ~/letsencrypt/config \
  --work-dir ~/letsencrypt/work --logs-dir ~/letsencrypt/logs        # against staging

A Mac that was asleep at a scheduled time runs the job when it wakes. Use the same password variable as the server's LaunchAgent: the hook writes the .p12 with it, and photon reload checks that the server can open it.

No public port 80 (DNS-01). When the Mac is not reachable on port 80 (behind NAT, a tunnel, or serving only HTTPS), prove control of the domain through DNS instead. For a domain on Amazon Route 53, install the plugin into Homebrew's certbot and replace --webroot -w … with --dns-route53:

"$(brew --prefix certbot)/libexec/bin/pip" install certbot-dns-route53
certbot certonly --dns-route53 -d example.com -d '*.example.com' …   # same dirs and --deploy-hook

It reads AWS credentials the usual way (~/.aws/credentials, AWS_PROFILE, or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, which then go in the renew LaunchAgent's EnvironmentVariables too); the IAM policy needs route53:ListHostedZones, route53:GetChange and route53:ChangeResourceRecordSets on the zone. DNS-01 is also the only way to get a wildcard certificate. Other DNS providers have their own certbot-dns-* plugins, and lego and acme.sh support most providers out of the box.

lego

# Webroot mode, while PhotonHTTP serves the site on port 80
lego --email you@example.com --domains example.com --domains www.example.com \
     --http --http.webroot /Users/me/Sites/example run \
     --run-hook "$HOME/letsencrypt/acme-deploy-hook.sh --config /Users/me/Sites/example/http-config.json"
# certificates land in ./.lego/certificates/example.com.crt (full chain) and .key
# renewals: the same command with `renew --renew-hook "…"` in place of `run --run-hook "…"`

acme.sh

acme.sh --issue -d example.com -w /Users/me/Sites/example
acme.sh --install-cert -d example.com \
  --fullchain-file ~/letsencrypt/example.com.fullchain.pem --key-file ~/letsencrypt/example.com.key \
  --reloadcmd "$HOME/letsencrypt/acme-deploy-hook.sh --cert $HOME/letsencrypt/example.com.fullchain.pem --key $HOME/letsencrypt/example.com.key --config /Users/me/Sites/example/http-config.json"

By hand

export SWS_P12_PASSWORD='a long random password'
scripts/acme-deploy-hook.sh --cert fullchain.pem --key privkey.pem --out certs/example.p12

That is this openssl command plus the checks and the atomic move. The legacy algorithms matter: SecPKCS12Import does not reliably accept OpenSSL 3's default AES/PBKDF2 encryption (scripts/make-test-identity.sh uses the same flags):

openssl pkcs12 -export \
  -inkey privkey.pem -in fullchain.pem \
  -out certs/example.p12 -passout env:SWS_P12_PASSWORD \
  -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1
chmod 600 certs/example.p12

-in must be the full chain (leaf first, then intermediates). Use Homebrew's /opt/homebrew/bin/openssl if /usr/bin/openssl (LibreSSL) rejects an option.

What the server does with a renewed file

A new .p12 written over the old path (made in a temporary file, then mved into place, so the server never reads half a file) is picked up by a reload: SIGHUP, photon reload, or the file watcher (on by default, reload.watch, within reload.interval). New HTTPS and HTTP/3 connections get the new certificate without a restart or dropped connections (see reload). stderr confirms it with reload: TLS identity PATH reloaded; if the new file does not load (wrong password, not PKCS#12) it prints warning: reload: cannot load TLS identity …; keeping the current TLS certificate and keeps serving the old one.

Binding to all interfaces and the firewall prompt

The default host is 127.0.0.1: only this Mac can connect. To serve your network or the internet, set "host": "0.0.0.0" (all IPv4 interfaces) or "::".

With the macOS application firewall on (System Settings → Network → Firewall), the first time an unsigned or newly built binary listens on a non-loopback address macOS asks "Do you want the application "photon" to accept incoming network connections?". Each rebuild changes the binary, so the prompt can come back. Options:

Loopback (127.0.0.1, ::1) never prompts, which is why every example and test here binds loopback. A server reached only through a local reverse proxy or a tunnel (Tailscale, Cloudflare Tunnel) can stay on loopback or bind only the tunnel's address.

HTTP/3 needs the UDP port open as well as TCP, in any firewall or router in front of the Mac.

Ports 80 and 443 without root

Since macOS 10.14 (Mojave), a non-root process may bind ports below 1024 on the wildcard address, so "host": "0.0.0.0" (or "::") with "port": 80 and "tls": {"port": 443} works as a normal user. Binding a specific address below 1024 can still fail with EACCES ("Permission denied"); bind the wildcard instead. Do not run the server as root.

Running as a LaunchAgent

A user LaunchAgent starts the server at login and restarts it if it exits. Save as ~/Library/LaunchAgents/com.example.photonhttp.plist (adjust paths):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.example.photonhttp</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/photon</string>
    <string>--config</string>
    <string>/Users/me/Sites/example/http-config.json</string>
  </array>
  <key>WorkingDirectory</key>
  <string>/Users/me/Sites/example</string>
  <key>EnvironmentVariables</key>
  <dict>
    <key>SWS_P12_PASSWORD</key>
    <string>…</string>
  </dict>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <dict>
    <key>SuccessfulExit</key>
    <false/>
  </dict>
  <key>ExitTimeOut</key>
  <integer>30</integer>
  <key>StandardOutPath</key>
  <string>/Users/me/Library/Logs/PhotonHTTP/stdout.log</string>
  <key>StandardErrorPath</key>
  <string>/Users/me/Library/Logs/PhotonHTTP/stderr.log</string>
</dict>
</plist>
mkdir -p ~/Library/Logs/PhotonHTTP
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.photonhttp.plist
photon restart --config /Users/me/Sites/example/http-config.json   # apply a config, no gap
launchctl kickstart -k gui/$(id -u)/com.example.photonhttp    # new process (a new binary)
launchctl bootout gui/$(id -u)/com.example.photonhttp         # stop and unload

Logs

KeyTypeDefaultMeaning
accessLogbool, string or objectofftrue: Common lines to stdout. A string: the path. false/null: off
accessLog.pathstring or null"stdout"A file (relative to the config file; appended to, created 0644; its directory must exist), "stdout" or "stderr". null writes no lines (metrics only)
accessLog.format"common" | "combined" | "json""common"Combined adds Referer and User-Agent; JSON lines include the duration
accessLog.metricsbool or pathoffServe Prometheus metrics at this path (true = /metrics)
accessLog.flushIntervalseconds > 01Longest a line waits in its buffer
accessLog.enabledbooltruefalse turns it off

The access log is outermost in the chain, so it records the final status of every response (error pages, auth rejections, proxied responses). Lines are buffered per connection and written by a background task; if the writer falls behind, lines are dropped (counted), never delayed. A graceful stop writes everything buffered. metrics is served to anyone who can reach the server; protect it with auth if that matters.

Rotation. The server does not rotate files itself. Move the file aside, then send SIGHUP: the log is reopened by its path, so the next lines go to a new file and the moved one is complete once the connections open before the signal have closed (each finishes its buffered lines into it).

mv logs/access.log logs/access.log.1
kill -HUP "$(pgrep -f 'photon --config /path/to/http-config.json')"

newsyslog signals a process through a pid file, which the server does not write; run the two commands above from a LaunchAgent with StartCalendarInterval instead (or have your own wrapper write a pid file).

Shutdown, restart and reload

Graceful restart

photon restart (or SIGUSR2 to the server's pid) applies a whole config file, restart-only keys included, inside the running process (#0144):

  1. The server reads, validates and builds the config as at startup (same file and command-line overrides): settings, protocols, the TLS identity (in memory only) and the handler chain. Any failure stops here and nothing changes.
  2. It binds the new listeners while the old ones still accept. A port that stays the same is never without a listener:
    • Cleartext on BSD sockets (the default transport): the new socket binds the same port with SO_REUSEPORT, which the old socket turns on only for the moment of the swap (another program binding the port still gets "address already in use"). The kernel sends new connections to the new socket; connections already queued on the old one are served, then it closes.
    • HTTPS and HTTP/3 (Network.framework, which cannot share a port), and cleartext with "transport": "nw": the running listener is handed to the new configuration as it is, when its address and ALPN stay the same. Its certificate comes from the same identity store, so a changed identity file applies to new handshakes as on a reload. Turning http2 on or off changes the HTTPS listener's ALPN: that listener closes and rebinds, a gap of a few milliseconds on the HTTPS port only.
    • A changed port (port, tls.port, http3.port, or host): the new port opens; the old one stops accepting and closes once the swap is done.
    • A port of 0 that was 0 before keeps the port it was given.
  3. The new listeners start accepting with the new settings (limits, timeouts, maxBodySize, protocols, chain).
  4. The old listeners stop accepting. Their connections go on for a second (so a connection accepted just before the swap gets its first request answered), then drain as on SIGTERM: HTTP/2 and HTTP/3 send GOAWAY, HTTP/1.1 closes idle keep-alive connections and finishes the request in flight with connection: close, tunnels end; whatever is still open after the new drainTimeout is cancelled. While the old connections drain, each set has its own maxConnections.

If a new listener cannot bind (its port is taken, a bad host), the listeners already bound for the restart close and the old ones keep serving: stderr and photon restart say restart failed, the running server keeps serving: listener http on 127.0.0.1:8081: Address already in use (errno 48), and the status file records "result": "failed" with "trigger": "restart". Success prints restarted; listening … on stderr (not stdout: the listening lines there are the startup ones) and records "result": "restarted".

Restarts and reloads run one at a time on the same task. A server started without http3 can turn it on by a restart, but its responses only advertise it (Alt-Svc) after a process restart. A client that keeps a connection idle across the swap may see it closed (as on any server closing idle keep-alive connections); HTTP clients retry such requests on a new connection.

A public server checklist