Getting started

On this page

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

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
OptionMeaning
--prefix DIRInstall to DIR/bin instead of /usr/local/bin. A writable DIR, such as ~/.local, needs no sudo
--version REFThe 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]
ArgumentDefaultMeaning
DIRcurrent directoryThe directory to serve
--port PORT8080The port to listen on; 0 picks any free port (the listening line shows which)
--host HOST127.0.0.1The 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