Skip to content

static-php/phpmicro

 
 

Repository files navigation

micro SAPI for PHP

English readme Chinese readme License

micro SAPI makes PHP self-executable, allowing you to run php-cli apps without any PHP installation.


micro is a SAPI module for PHP that allows you to create self-executable PHP binaries. By concatenating the micro SAPI binary with your PHP source code or PHAR files, you can run PHP applications without requiring a separate PHP installation.

micro SAPI works similarly to the built-in CLI SAPI, you can run almost all CLI-based PHP applications with it.

Quick Start

We recommend building micro SAPI using static-php-cli to include popular extensions like pdo, openssl, mbstring, and more.

You can first try pre-built micro SAPI binaries from hosted by static-php.dev server:

Platform Download Link
Linux x86_64 micro.sfx
Linux aarch64 micro.sfx
Windows x86_64 micro.sfx
macOS x86_64 micro.sfx
macOS arm64 micro.sfx

Then prepare your PHP code or PHAR cli app archive, and concatenate them:

<?php // myapp.php
echo "Hello, this is my awesome app." . PHP_EOL;
# On Linux/macOS:
cat /path/to/micro.sfx myapp.php > myapp
chmod +x ./myapp
./myapp
# shows "Hello, this is my awesome app."

# or on Windows:
COPY /b \path\to\micro.sfx + myapp.php myapp.exe
.\myapp.exe
# shows "Hello, this is my awesome app."

Build statically linked micro.sfx

Since we need to build micro.sfx as a standalone and portable binary, the best way is to build it statically. That will make sure it can run on most systems without worrying about missing shared libraries.

You can follow the steps in static-php.dev docs to build your own static PHP binary with micro SAPI included:

  1. First, download and install static-php-cli by following the installation guide.
  2. Next, use the spc command to build a static PHP binary with micro SAPI:
# linux/macOS
EXTENSIONS="bcmath,phar,openssl,mbstring"
./spc doctor --auto-fix
./spc download --for-extensions=$EXTENSIONS --with-php=8.4
./spc build $EXTENSIONS --build-micro

# windows (PowerShell)
.\spc.exe doctor --auto-fix
.\spc.exe download --for-extensions="bcmath,phar,openssl,mbstring" --with-php=8.4
.\spc.exe build "bcmath,phar,openssl,mbstring" --build-micro

Documentation

For more details about micro SAPI, please refer to the https://micro.static-php.dev docs.

Credit

This project originally forked from easysoft/phpmicro and adapted to work with static-php-cli.

Thanks to all the contributors of phpmicro and static-php-cli projects.

Open-Source License

This project is licensed under Apache-2.0 License. See the LICENSE file for details.

When building static PHP with static-php-cli, the resulting binary may include other open-source components. Please refer to the static-php-cli LICENSE description.

About

micro SAPI makes PHP self-executable, allowing you to run php-cli apps without any PHP installation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 78.9%
  • PHP 14.7%
  • M4 3.7%
  • JavaScript 2.0%
  • Makefile 0.7%