PHPackages                             crazywhalecc/static-php-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. crazywhalecc/static-php-cli

ActiveLibrary[CLI &amp; Console](/categories/cli)

crazywhalecc/static-php-cli
===========================

Build single static PHP binary, with PHP project together, with popular extensions included.

2.8.3(1mo ago)1.8k13.9k↓14.4%365[8 issues](https://github.com/crazywhalecc/static-php-cli/issues)[4 PRs](https://github.com/crazywhalecc/static-php-cli/pulls)MITPHPPHP &gt;= 8.3

Since Apr 23Pushed 1mo ago21 watchersCompare

[ Source](https://github.com/crazywhalecc/static-php-cli)[ Packagist](https://packagist.org/packages/crazywhalecc/static-php-cli)[ Fund](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md)[ RSS](/packages/crazywhalecc-static-php-cli/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (81)Used By (0)

static-php-cli
==============

[](#static-php-cli)

[![Chinese readme](https://camo.githubusercontent.com/9737edd7526c0e955f0d434c401e671c86cd120a2b06b8c4b50b1f7b11a917f5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f524541444d452d2545342542382541442545362539362538372532302546302539462538372541382546302539462538372542332d6d6f63636173696e3f7374796c653d666c61742d737175617265)](README-zh.md)[![English readme](https://camo.githubusercontent.com/5455baad74f1690f737f9d248d450996345500c939f7b91a4e5bc7ea02dfc5ab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f524541444d452d456e676c6973682532302546302539462538372541432546302539462538372541372d6d6f63636173696e3f7374796c653d666c61742d737175617265)](README.md)[![Releases](https://camo.githubusercontent.com/bb3d7ef861a2b15147490ec2e2a18a4ae0190d8dcec7f21e26b5db195c0a48be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372617a797768616c6563632f7374617469632d7068702d636c693f696e636c7564655f70726572656c6561736573266c6162656c3d52656c65617365267374796c653d666c61742d737175617265)](https://github.com/crazywhalecc/static-php-cli/releases)[![CI](https://camo.githubusercontent.com/043217146098538ce41ff69c446a57348fa6d8fc669ed58b56f74577573973be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6372617a797768616c6563632f7374617469632d7068702d636c692f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d4275696c6425323054657374267374796c653d666c61742d737175617265)](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/a7e65aee57b11d28e4caff8b945729a66be0bb663f7f93bd24c5aa65699f148e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)

**static-php-cli** is a powerful tool designed for building static, standalone PHP runtime with popular extensions.

Features
--------

[](#features)

- 🐘 Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5
- 👜 Build single-file PHP executable with zero dependencies
- 🍔Build **[phpmicro](https://github.com/dixyes/phpmicro)** self-extracting executables (combines PHP binary and source code into one file)
- 💊 Automatic build environment checker with auto-fix capabilities
- ⚡ `Linux`, `macOS`, `FreeBSD`, `Windows` support
- 🔧 Configurable source code patching
- 📚 Intelligent dependency management
- 📦 Self-contained `spc` executable (built with [box](https://github.com/box-project/box))
- 🔥 Support 100+ popular [extensions](https://static-php.dev/en/guide/extensions.html)
- 💾 UPX compression support (reduces binary size by 30-50%)

**Single-file standalone php-cli:**

[![out1](https://private-user-images.githubusercontent.com/20330940/295232925-01a2e60f-13b0-4242-a645-f7afa4936396.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJ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TIwMjYwMzI0VDE1MzczN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg4OTI2ZDE1ZjI5ZWY0YWU0NzZjNmU2MzE3OTQyMTM5ZjkxNDczMjMyZWYyODgyMzE0ZmJlMWM4ZDIzN2RkMTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.4ljRk9PrHq43F7E6QuqpmMI5ymZnbl49uORC5IDbOpE)**Combine PHP code with PHP interpreter using phpmicro:**

[![out2](https://private-user-images.githubusercontent.com/20330940/295389383-46b7128d-fb72-4169-957e-48564c3ff3e2.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNjY5NTcsIm5iZiI6MTc3NDM2NjY1NywicGF0aCI6Ii8yMDMzMDk0MC8yOTUzODkzODMtNDZiNzEyOGQtZmI3Mi00MTY5LTk1N2UtNDg1NjRjM2ZmM2UyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDE1MzczN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgwZGNkMDZjMzgwNzg2YWIxMzJhMmJmYmMxOTkyMDg5YWE2MjU1ZGYyNjU5YzJmMzYxOTg0YzM1ZjIwMmI1MGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.WokHgNKbFv6IQbV6v2mGoq7ExrpOIvKQVDwDqW9BC40)](https://private-user-images.githubusercontent.com/20330940/295389383-46b7128d-fb72-4169-957e-48564c3ff3e2.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNjY5NTcsIm5iZiI6MTc3NDM2NjY1NywicGF0aCI6Ii8yMDMzMDk0MC8yOTUzODkzODMtNDZiNzEyOGQtZmI3Mi00MTY5LTk1N2UtNDg1NjRjM2ZmM2UyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzI0VDE1MzczN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgwZGNkMDZjMzgwNzg2YWIxMzJhMmJmYmMxOTkyMDg5YWE2MjU1ZGYyNjU5YzJmMzYxOTg0YzM1ZjIwMmI1MGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.WokHgNKbFv6IQbV6v2mGoq7ExrpOIvKQVDwDqW9BC40)Quickstart
----------

[](#quickstart)

### 1. Download spc binary

[](#1-download-spc-binary)

```
# For Linux x86_64
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64
# For Linux aarch64
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64
# macOS x86_64 (Intel)
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64
# macOS aarch64 (Apple)
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64
# Windows (x86_64, win10 build 17063 or later, please install VS2022 first)
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe
```

For macOS and Linux, add execute permission first:

```
chmod +x ./spc
```

### 2. Build Static PHP

[](#2-build-static-php)

First, create a `craft.yml` file and specify which extensions you want to include from [extension list](https://static-php.dev/en/guide/extensions.html) or [command generator](https://static-php.dev/en/guide/cli-generator.html):

```
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5
php-version: 8.4
# Put your extension list here
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
sapi:
  - cli
  - micro
  - fpm
download-options:
  prefer-pre-built: true
```

Run command:

```
./spc craft

# Output full console log
./spc craft --debug
```

### 3. Static PHP usage

[](#3-static-php-usage)

Now you can copy binaries built by static-php-cli to another machine and run with no dependencies:

```
# php-cli
buildroot/bin/php -v

# phpmicro
echo '
