Skip to main content

Installation

3 min read Last updated
On this page

All methods need PHP 8.5+, except Quick launch and Docker, which bring their own PHP.

Which method?

GoalUse
New project with tests + scriptsGetting Started
Add to existing Composer projectComposer require
Run a single file, no setupPHAR
No PHP, no DockerQuick launch
No PHP, Docker availableDocker
Reproducible dev shellsNix

To start a new project from the skeleton, follow Getting Started. To add Phel to an existing project:

composer require phel-lang/phel-lang
vendor/bin/phel init my-app    # scaffold phel-config.php + src/

Then run every command as vendor/bin/phel <cmd>, for example vendor/bin/phel repl. phel init has more layouts and templates: see CLI Commands.

PHAR (no project setup)

The PHAR is a single file that runs without Composer. Use it for quick experiments, one-off CI jobs, or to try the language.

curl -L https://phel-lang.org/phar -o phel.phar
php phel.phar --version

Every command works the same way:

php phel.phar repl
php phel.phar run src/main.phel
php phel.phar test --filter foo

To make it available everywhere:

chmod +x phel.phar
sudo mv phel.phar /usr/local/bin/phel
phel repl

Quick launch (no PHP, no Docker)

One command, no PHP and no container. Linux and macOS, x86_64 and arm64.

bash <(curl -sL https://phel-lang.org/get) repl

It downloads a static PHP build and the Phel PHAR into a private temporary folder, checks the PHP download against a pinned SHA-256, and runs your command. Nothing needs root. Later runs reuse the download.

Do not pipe it into bash (curl ... | bash): bash takes over stdin and the REPL exits at once. On other shells, download the script first with curl -sL https://phel-lang.org/get -o /tmp/phel-get, then run bash /tmp/phel-get repl.

To keep phel on PATH for the shell session:

source <(curl -sL https://phel-lang.org/get)
phel run src/main.phel
VariableDefaultEffect
PHEL_VERSIONlatestPin a Phel release, e.g. 0.54.0
PHP_VERSION8.5.8Pin a static PHP build. Only the default has a pinned checksum
PREFIX${TMPDIR}/phel-quick, or /tmp/phel-quick-$UIDWhere everything is downloaded
PHEL_FORCE01 downloads again instead of reusing

Differences from a normal install:

  • No readline, so the REPL has no history or arrow keys. Install rlwrap and the script uses it.
  • No OPcache, so each run compiles again.
  • Fixed extensions: json, mbstring, curl, openssl, gd, gmp, bcmath, pdo_mysql, pdo_pgsql, pdo_sqlite, redis, soap, sockets and zip. No PECL, no php.ini.
  • No Windows. Use WSL or Docker.

The script runs on your machine, so read it first. Remove everything with rm -rf "${TMPDIR:-/tmp}/phel-quick"*.

Docker (no PHP required)

Open a live Phel REPL with no files and no install:

docker run --rm -it php:8.5-cli sh -c \
  "curl -sL https://phel-lang.org/phar -o /tmp/phel.phar && php /tmp/phel.phar repl"

The container downloads the PHAR again on every run, so this suits a first try, not daily use.

For a Composer project, use the official composer image, which ships PHP and Composer:

docker run --rm -it -v "$PWD":/app -w /app composer \
  create-project --stability dev phel-lang/cli-skeleton example-app

cd example-app

# Start the REPL
docker run --rm -it -v "$PWD":/app -w /app composer composer repl

Nix

Use Nix for reproducible dev environments. Phel is in nixpkgs: see phel on search.nixos.org or the package source.

No Nix yet? Install it with the Determinate Systems installer or the official installer.

Ad-hoc shell

nix shell nixpkgs#phel
phel repl
Note

The nixpkgs version can be behind the latest release. Check it with nix eval nixpkgs#phel.version. For the newest release, use Composer or the PHAR.

Project shell.nix

Pin PHP and Composer for the whole team:

{ pkgs ? import <nixpkgs> { } }:

pkgs.mkShell {
  packages = with pkgs; [
    php85
    php85Packages.composer
  ];
}

Then run nix-shell and use Composer as normal.

Verify install

Run doctor with the method you installed:

vendor/bin/phel doctor    # Composer
php phel.phar doctor      # PHAR
phel doctor               # Nix / global

It checks the PHP extensions Phel needs (json, mbstring, readline), your source and test directories, OPcache, and the cache size, and names anything that is missing.