Let's Encrypt certificates (built-in ACME)

On this page

With a tls.acme block, photon gets its HTTPS certificate from Let's Encrypt (or another ACME CA) by itself, keeps it in a folder next to the config, and renews it in the background before it expires. There is no certbot, no PKCS#12 file, no password and no deploy hook. The same certificate serves HTTPS and HTTP/3, and a renewal swaps it in without a restart.

{
  "host": "0.0.0.0",
  "port": 80,
  "root": "Public",
  "tls": {
    "port": 443,
    "acme": {
      "email": "admin@example.com",
      "domains": ["example.com", "www.example.com"],
      "directory": "letsencrypt-staging",
      "agreeToTerms": true,
      "redirectHTTP": true
    }
  },
  "http3": true
}

Root/http-config.acme.json is the same example, with the names taken from hosts.

The built-in client uses the HTTP-01 challenge. It is the simplest way to run one Mac with its own public names. When to use certbot instead covers the cases it does not handle.

Requirements

The first time an unsigned binary listens on a public address, macOS may ask whether it may accept incoming connections (Binding to all interfaces and the firewall prompt).

Staging first

Start with "directory": "letsencrypt-staging". Staging issues certificates from an untrusted test root, so browsers warn, but its rate limits are generous. Production's are strict, and a misconfigured port 80 can use them up in a few failed tries. Once staging issues a certificate (photon cert status shows issuer: … (STAGING) …), switch to "letsencrypt" and reload. Changing the directory starts a new order. The state folder keeps one account per CA, so the staging account is not reused.

directory takes:

ValueCA
"letsencrypt" (default)Let's Encrypt production, https://acme-v02.api.letsencrypt.org/directory
"letsencrypt-staging"Let's Encrypt staging, https://acme-staging-v02.api.letsencrypt.org/directory
an https:// URLAny RFC 8555 CA: ZeroSSL, Google Trust Services (both need EAB), a private CA, or Pebble

Rate limits

Let's Encrypt limits, among other things, certificates per registered domain per week, duplicate certificates (the same set of names), new orders and failed validations per account and name per hour. See Rate limits. The server stays well inside them:

Avoid loops that defeat this: don't delete the state folder to "start over", and don't force renewals in a script. Test on staging.

The state directory

Keys, the certificate and the account live in stateDirectory (default acme, relative to the config file's folder, even when --root is given):

FileContents
account-key.pemThe ACME account's P-256 key (PKCS#8). Losing it loses the account, not the certificate
certificate-key.pemThe certificate's private key
certificate.pemThe chain as the CA sent it (leaf first)
metadata.jsonDirectory URL, account URL, names, profile, issue and last-success times

The folder is created 0700 and every file is written 0600: to a temporary file, then fsync and rename, so a crash never leaves half a key. The folder is tightened back to 0700 at every start. Nothing goes into the keychain, and no PKCS#12 file is written: the identity is built in memory. Back the folder up like any private key. Do not commit it; the repository's .gitignore covers Root/acme/.

To move it, set stateDirectory and move the folder while the server is stopped. To use another account, point at an empty folder. Never share one folder between two running servers.

Startup

At startup the server loads the state folder (no network):

startupUntil the first certificate is issued
"placeholder" (default)HTTPS and HTTP/3 serve a self-signed certificate for the names (issuer PhotonHTTP placeholder), which browsers reject. The real one replaces it as soon as it is issued, with no restart
"wait"Only the cleartext port listens (answering challenges, and serving or redirecting the site). Once the certificate is issued, a graceful restart adds the HTTPS and HTTP/3 listeners and prints their listening … (https) lines. No client ever sees the placeholder

Issuance usually takes a few seconds. The cleartext port never waits for it, so the CA can always reach the challenge.

Redirect HTTP to HTTPS

"redirectHTTP": true answers every cleartext request with 308 Permanent Redirect to https://HOST/PATH?QUERY on port 443. Give a number ("redirectHTTP": 8443) when HTTPS is reached on another port. Requests to /.well-known/acme-challenge/ are never redirected. Requests arriving over TLS or QUIC pass through. Without redirectHTTP (the default), the cleartext port serves the site too.

To also tell browsers to stay on HTTPS, add HSTS (TLS → HSTS) once the real certificate works.

Renewal

The renewal loop runs inside the server and stops with it:

Each renewal swaps the certificate into the running HTTPS and HTTP/3 listeners. New handshakes get it; open connections keep the one they negotiated. Every step goes to stderr, for example:

photon: acme: requesting a certificate for example.com,www.example.com from https://acme-v02.api.letsencrypt.org/directory
photon: acme: certificate for example.com,www.example.com issued, expires 2027-03-02T12:00:00Z (issuer R11, Let's Encrypt)
photon: acme: renewal window for example.com,www.example.com from the CA: 2027-01-31T… to 2027-02-02T…; renewing at 2027-02-01T…
photon: acme: certificate for example.com,www.example.com failed (attempt 1): …; keeping the current certificate (expires …); retrying at …

Commands

photon cert status [--config FILE] [--json]
photon cert renew  [--force] [--config FILE] [--timeout SECONDS]

Like the other control commands, these find the server through its status file (statusFile, default run/status.json) and signal its pid. There is no control socket.

Reload and restart

ChangeTakes effect
domains (or the hosts names it defaults to), directory, email/contact, profile, externalAccountBinding, caCertificates, stateDirectoryReload. The server makes a new certificate manager and orders a certificate if the stored one does not cover the new names or comes from another CA. The current certificate keeps serving until then. photon check reports can hot-reload: tls.acme changed
redirectHTTPReload (it is part of the request chain)
startupOnly at startup
tls.portRestart, as with tls.identity
Switching between tls.identity and tls.acme, or adding or removing tlsRestart (photon restart), like adding or removing tls. A server that started without tls.acme cannot add it in a graceful restart: stop and start it (launchctl kickstart -k …)

Other CAs

Reference

KeyTypeDefaultMeaning
tls.acmeobject–Get the certificate over ACME. Not together with tls.identity / tls.password / tls.passwordEnv
tls.acme.emailstring or arraynoneContact address(es), sent as mailto: URLs. Optional (Let's Encrypt no longer sends expiry emails)
tls.acme.contactarraynoneContact URLs (mailto: only), in addition to email
tls.acme.domainsarray of stringsnames in hostsNames (or IP addresses) on the certificate. No wildcards
tls.acme.directorystring"letsencrypt""letsencrypt", "letsencrypt-staging" or an https:// directory URL
tls.acme.agreeToTermsbool (required true)falseAccept the CA's terms of service
tls.acme.stateDirectorystring"acme"Folder for keys, chain and metadata, relative to the config file
tls.acme.profilestringnoneACME profile, e.g. "shortlived"
tls.acme.redirectHTTPbool or portfalseRedirect cleartext requests to HTTPS (true = port 443)
tls.acme.startupstring"placeholder""placeholder" or "wait" (Startup)
tls.acme.externalAccountBindingobjectnonekeyID and hmacKey or hmacKeyEnv
tls.acme.caCertificatesstringsystem rootsPEM roots to trust for the CA's directory

Troubleshooting

Start with photon cert status. Its last error is the CA's problem document, which names the failing name.

SymptomCause and fix
unauthorized / incorrectResponse, Invalid response from http://NAME/.well-known/acme-challenge/…The CA reached something else on port 80: a router forwarding to another machine, another web server, or a CDN. curl -i http://NAME/.well-known/acme-challenge/test from outside should give this server's 404
connection / Timeout during connectPort 80 is closed: router forwarding, a firewall, or an ISP that blocks inbound port 80 (then use certbot with DNS-01)
dns / NXDOMAIN / No valid IP addresses foundThe name doesn't resolve publicly yet, or an AAAA record points to an address that doesn't reach the Mac. Remove a wrong AAAA record
caaA CAA record on the domain forbids this CA. Add letsencrypt.org (or your CA) to it
rateLimitedProduction limit reached. The server waits for the CA's Retry-After by itself; test on staging meanwhile
externalAccountRequiredThe CA needs externalAccountBinding
HTTPS shows PhotonHTTP placeholderNo certificate yet: see last error. With startup: "wait", HTTPS isn't listening yet instead
"tls.acme.stateDirectory": cannot use … at startupThe folder can't be created or read: wrong owner, or a file in its place
Browser warns (STAGING)You are still on letsencrypt-staging. Switch directory and reload

The server never retries faster than the backoff, so fix the cause and then run photon cert renew --force (or reload) instead of restarting in a loop.

When to use certbot instead

Use certbot (or lego, acme.sh) with scripts/acme-deploy-hook.sh and tls.identity when:

Switching between the two is a config edit and photon restart.