Getting started
Install the photon command, serve a folder, then grow into a config file when you need TLS,
compression, logs or more than one site.
Requirements
- macOS 15 or later for the installer below. PhotonHTTP also runs on Linux (HTTP/1.1, HTTP/2 and HTTP/3); see Running on Linux for building and deploying there.
- A Swift 6.4 toolchain, from Xcode or swift.org. The installer builds from source.
Install
One command clones the repository, builds a
release binary with your Swift toolchain and installs photon to /usr/local/bin, which is on
every Mac's default PATH. Only the final copy uses sudo, and only when /usr/local/bin is not
writable: the installer says so and asks for your password. It never edits your shell files.
curl -fsSL https://photon-http.sstools.co/install.sh | bash
Pass options after bash -s --:
curl -fsSL https://photon-http.sstools.co/install.sh | bash -s -- --prefix ~/opt --version main
| Option | Meaning |
|---|---|
--prefix DIR | Install to DIR/bin instead of /usr/local/bin. A writable DIR, such as ~/.local, needs no sudo |
--version REF | The git tag or branch to build. Default main |
From a checkout of the repository, run the same installer directly:
scripts/install.sh
Check that your shell finds it:
photon --help
If it says command not found, the install folder is not on your PATH (only possible with
--prefix; the installer prints a warning). Add it in your shell's startup file, e.g.
~/.zshrc:
export PATH="$HOME/.local/bin:$PATH" # for --prefix ~/.local
Uninstall by deleting the binary: sudo rm /usr/local/bin/photon (or DIR/bin/photon with
--prefix). It has no other files and no dependencies outside the system.
Serve a folder
photon serve serves a directory as a static website: the current directory unless you name
one. / and every directory serve their index.html.
cd ~/Sites/example
photon serve
# listening 127.0.0.1:8080
Open http://127.0.0.1:8080/ in a browser, or check it with curl http://127.0.0.1:8080/.
Press Ctrl-C to stop the server.
photon serve [DIR] [--port PORT] [--host HOST]
| Argument | Default | Meaning |
|---|---|---|
DIR | current directory | The directory to serve |
--port PORT | 8080 | The port to listen on; 0 picks any free port (the listening line shows which) |
--host HOST | 127.0.0.1 | The address to bind. 127.0.0.1 means only this Mac can connect; 0.0.0.0 shares the site on your network |
photon serve public --port 8000 # serve ./public on port 8000
photon serve ~/Sites/example --port 0 # any free port
photon serve . --host 0.0.0.0 # reachable from other devices on your network
photon serve always does plain static serving: it ignores any http-config.json in the
folder. With the macOS firewall on, the first time a newly built photon listens on 0.0.0.0
macOS asks whether to accept incoming connections; see
binding to all interfaces and the firewall prompt.
When you need more: a config file
TLS, HTTP/2 and HTTP/3, compression, access logs, virtual hosts, authentication and the reverse
proxy are configured in one JSON file, http-config.json, which you pass with
photon --config. Every key is optional; relative paths resolve against the file's directory.
{
"root": "public",
"compression": true,
"caching": { "maxAge": 600 },
"errorPages": { "404": "errors/404.html" },
"accessLog": { "path": "logs/access.log", "format": "combined" }
}
photon --config http-config.json
# listening 127.0.0.1:8080
A running server picks up edits to the file by itself, or on SIGHUP, without dropping
requests. photon check validates a config, and photon reload, photon status and
photon restart talk to the running server. Every key and command is in
Running on a Mac.
Next steps
- Static websites: caching and ETags, Range, error pages, compression, virtual hosts and authentication.
- Running on a Mac: every command and config key, certificates, ports 80 and 443, LaunchAgents, logs, reload.
- Running on Linux: building for a Linux server, HTTPS and HTTP/3, systemd.
- TLS: HTTPS, HTTP/2 and HTTP/3 with a PKCS#12 identity loaded in memory, never the keychain.
- Dynamic websites: proxy paths to a local app, or write handlers in Swift with Router and WebSockets.
- Choosing components: build your own server as a Swift package from the parts you need.
- Overview and architecture: how the pieces fit.