Install Common (CL)
One C file, no dependencies. Build it in a second, then serve any folder of pages.
git clone https://github.com/commonlang/cl.git
cd cl
make
./cl serve 8000 examples
Then open localhost:8000/hello. Any folder of .html pages works the same way. SQLite support switches on by itself when SQLite is installed, which it is on macOS and most Linux systems.
- Install a compiler, make, and SQLite headers:
# Debian, Ubuntu, Mint sudo apt install build-essential git libsqlite3-dev # Fedora sudo dnf install gcc make git sqlite-devel # Arch sudo pacman -S base-devel git sqlite # Alpine apk add build-base git sqlite-dev - Build and install:
git clone https://github.com/commonlang/cl.git cd cl make sudo make install - No sudo?
make install PREFIX=$HOME/.localand make sure~/.local/binis on your PATH.
On a web server
The built-in server is for development. For the internet, run Common the way PHP was first run: behind a real web server. Pick whichever you already have.
Keep cl serve running and let Caddy add the domain and TLS.
example.com {
reverse_proxy localhost:8000
}
Run cl serve 8000 /var/www/site under systemd so it restarts on reboot.
Copy the cl binary into cgi-bin/ and add to .htaccess:
Action common /cgi-bin/cl
AddHandler common .html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [L]
The rewrite lines give you clean URLs like /about.
location ~ \.html$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/fcgiwrap.socket;
}
location / {
try_files $uri $uri.html /index.html;
}
Point fcgiwrap at cl cgi. In CGI mode Common reads the standard variables, runs the page named by SCRIPT_FILENAME, and turns go to into a 303.
- Keep your data private. Common's own server never sends databases, secrets or saved email. Behind Apache or nginx, add the same rule (see
docs/deploy.md), or keep the database in a folder outside the site. - Lock the files down:
chmod 600 site.db cl.secret - Expect spam on open forms. Email is limited to 20 an hour, but forms like a guestbook have no rate limit yet.
Check it works
cl words # every word in the language
make test # the test suite
make sanitize # the same suite under AddressSanitizer and UBSan
Full details: docs/install.md and docs/deploy.md in the repository.