Build standalone portable PHP binaries on Linux, macOS, Windows, with PHP project together, with popular extensions included.
See the codeStaticPHP is a powerful tool designed for building portable executables including PHP, extensions, and more.
[!IMPORTANT] We are preparing to release v3, which will include a project rename from static-php-cli to StaticPHP. And this branch is for v3. For v2, please check the v2 branch. Please update your references and stay tuned for the official release.
Linux, macOS, Windows supportspc executable for easy self-installationSingle-file standalone php-cli:
Combine PHP code with PHP interpreter using phpmicro:
# For Linux x86_64
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64
# For Linux aarch64
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64
# macOS x86_64 (Intel)
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64
# macOS aarch64 (Apple)
curl -fsSL -o spc https://dl.static-php.dev/v3/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/v3/spc-bin/nightly/spc-windows-x64.exe
For macOS and Linux, add execute permission first:
chmod +x ./spc
First, create a craft.yml file and specify which extensions you want to include from extension list or command generator:
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (pre-release)
php-version: 8.5
# 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
download-options:
parallel: 10
Run command:
./spc craft
# Output full console log
./spc craft -vvv
Now you can copy binaries built by StaticPHP to another machine and run with no dependencies:
# php-cli
buildroot/bin/php -v
# phpmicro
echo '<?php echo "Hello world!\n";' > a.php
./spc micro:combine a.php -O my-app
./my-app
The current README contains basic usage. For the complete feature set of StaticPHP, see https://static-php.dev.
If you do not want to build yet or just want to test first, you can download example pre-compiled artifacts from Actions or from a self-hosted server.
We offer 2 types of extension sets for each PHP version:
WIP
When the direct-download binaries above cannot meet your needs, you can use GitHub Actions to easily build a statically compiled PHP while defining your own extension list.
CI.Run workflow, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. bcmath,curl,mbstring)Artifacts.If you enable debug, all logs will be output at build time, including compiled logs, for troubleshooting.
We are also planning to provide a reusable GitHub Actions workflow in the future, so that you can easily build static PHP in your own repository, without forking this project.
If the extension you need is missing, you can create an issue. If you are familiar with this project, you are also welcome to initiate a pull request.
If you want to contribute documentation, please just edit in docs/.
You can sponsor me or my project from GitHub Sponsor. A portion of your donation will be used to maintain the static-php.dev server.
Special thanks to sponsors below:
JetBrains provides core contributors with OSS Development Licenses
This project itself is licensed under MIT. Some newly added extensions and dependencies may originate from other projects. The headers of those source files may also include additional LICENSE and AUTHOR information.
Please use the bin/spc dump-license command to export the open source licenses used in the project after compilation,
and comply with the corresponding project's LICENSE.
410 followers · starred Aug 2023
223 followers · starred Oct 2023
1,338 followers · starred Dec 2023
4,384 followers · starred Nov 2023
Build standalone portable PHP binaries on Linux, macOS, Windows, with PHP project together, with popular extensions included.
See the codeStaticPHP is a powerful tool designed for building portable executables including PHP, extensions, and more.
[!IMPORTANT] We are preparing to release v3, which will include a project rename from static-php-cli to StaticPHP. And this branch is for v3. For v2, please check the v2 branch. Please update your references and stay tuned for the official release.
Linux, macOS, Windows supportspc executable for easy self-installationSingle-file standalone php-cli:
Combine PHP code with PHP interpreter using phpmicro:
# For Linux x86_64
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64
# For Linux aarch64
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64
# macOS x86_64 (Intel)
curl -fsSL -o spc https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64
# macOS aarch64 (Apple)
curl -fsSL -o spc https://dl.static-php.dev/v3/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/v3/spc-bin/nightly/spc-windows-x64.exe
For macOS and Linux, add execute permission first:
chmod +x ./spc
First, create a craft.yml file and specify which extensions you want to include from extension list or command generator:
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (pre-release)
php-version: 8.5
# 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
download-options:
parallel: 10
Run command:
./spc craft
# Output full console log
./spc craft -vvv
Now you can copy binaries built by StaticPHP to another machine and run with no dependencies:
# php-cli
buildroot/bin/php -v
# phpmicro
echo '<?php echo "Hello world!\n";' > a.php
./spc micro:combine a.php -O my-app
./my-app
The current README contains basic usage. For the complete feature set of StaticPHP, see https://static-php.dev.
If you do not want to build yet or just want to test first, you can download example pre-compiled artifacts from Actions or from a self-hosted server.
We offer 2 types of extension sets for each PHP version:
WIP
When the direct-download binaries above cannot meet your needs, you can use GitHub Actions to easily build a statically compiled PHP while defining your own extension list.
CI.Run workflow, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. bcmath,curl,mbstring)Artifacts.If you enable debug, all logs will be output at build time, including compiled logs, for troubleshooting.
We are also planning to provide a reusable GitHub Actions workflow in the future, so that you can easily build static PHP in your own repository, without forking this project.
If the extension you need is missing, you can create an issue. If you are familiar with this project, you are also welcome to initiate a pull request.
If you want to contribute documentation, please just edit in docs/.
You can sponsor me or my project from GitHub Sponsor. A portion of your donation will be used to maintain the static-php.dev server.
Special thanks to sponsors below:
JetBrains provides core contributors with OSS Development Licenses
This project itself is licensed under MIT. Some newly added extensions and dependencies may originate from other projects. The headers of those source files may also include additional LICENSE and AUTHOR information.
Please use the bin/spc dump-license command to export the open source licenses used in the project after compilation,
and comply with the corresponding project's LICENSE.
410 followers · starred Aug 2023
223 followers · starred Oct 2023
1,338 followers · starred Dec 2023
4,384 followers · starred Nov 2023