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 the compiler if you do not have it. A dialog opens, click Install.
xcode-select --install - Build and install:
git clone https://github.com/commonlang/cl.git cd cl make sudo make install # copies cl to /usr/local/bin - Check:
cl wordsprints the language, andcl serve 8000 examplesserves the example page at/hello.
- 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.
Option A: WSL (recommended)
- Open PowerShell as administrator, run
wsl --install, restart. - Open the Ubuntu app from the Start menu and follow the Linux steps.
- In your Windows browser,
http://localhost:8000/reaches the server inside WSL.
Option B: native build with MinGW
- Get w64devkit: unzip it anywhere and run
w64devkit.exefor a shell with gcc and make. - Build:
git clone https://github.com/commonlang/cl.git cd cl gcc -O2 -o common.exe src/cl.c -lws2_32 - Run
common.exe serve 8000 examples. The binary iscommon.exeon Windows, becausecl.exeis already Microsoft's C compiler.
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.