Files
static-php-cli/en/guide/sapi-reference.html

78 lines
58 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>PHP SAPI Reference | StaticPHP</title>
<meta name="description" content="A powerful tool designed for building portable executables including PHP, extensions, and more.">
<meta name="generator" content="VitePress v2.0.0-alpha.18">
<link rel="preload stylesheet" href="/assets/style.C4OPn_QV.css" as="style">
<link rel="preload stylesheet" href="/vp-icons.css" as="style">
<script type="module" src="/assets/app.Bw02Lh2k.js"></script>
<link rel="preload" href="/assets/inter-roman-latin.Cy4MYw_J.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/assets/chunks/theme.C_odZu9O.js">
<link rel="modulepreload" href="/assets/chunks/framework.DrNIf5Lg.js">
<link rel="modulepreload" href="/assets/en_guide_sapi-reference.md.p2zEyiLe.lean.js">
<script id="check-dark-mode">(()=>{let e=localStorage.getItem(`vitepress-theme-appearance`)||`auto`,t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;(!e||e===`auto`?t:e===`dark`)&&document.documentElement.classList.add(`dark`)})();</script>
<script id="check-mac-os">document.documentElement.classList.toggle(`mac`,/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-0cf61682><!--[--><!--]--><!--[--><span tabindex="-1" data-v-414181b2></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-414181b2>Skip to content</a><!--]--><!----><header class="VPNav" data-v-0cf61682 data-v-9f75dce3><div class="VPNavBar has-sidebar top" data-v-9f75dce3 data-v-9ca1369d><div class="wrapper" data-v-9ca1369d><div class="container" data-v-9ca1369d><div class="title" data-v-9ca1369d><div class="VPNavBarTitle has-sidebar" data-v-9ca1369d data-v-1e38c6bc><a class="title" href="/en/" data-v-1e38c6bc><!--[--><!--]--><!--[--><img class="VPImage logo" src="/images/static-php_nobg.png" alt data-v-8426fc1a><!--]--><span data-v-1e38c6bc>StaticPHP</span><!--[--><!--]--></a></div></div><div class="content" data-v-9ca1369d><div class="content-body" data-v-9ca1369d><!--[--><!--]--><div class="VPNavBarSearch search" data-v-9ca1369d data-v-2fc7f2c6><!--[--><button type="button" class="VPNavBarSearchButton" aria-label="Search" aria-keyshortcuts="/ control+k meta+k" data-v-2fc7f2c6 data-v-baa3be99><span class="vpi-search" aria-hidden="true" data-v-baa3be99></span><span class="text" data-v-baa3be99>Search</span><span class="keys" aria-hidden="true" data-v-baa3be99><kbd class="key-cmd" data-v-baa3be99></kbd><kbd class="key-ctrl" data-v-baa3be99>Ctrl</kbd><kbd data-v-baa3be99>K</kbd></span></button><button type="button" class="VPNavBarAskAiButton" aria-label="Ask AI" aria-keyshortcuts="control+i meta+i" data-v-2fc7f2c6 data-v-4eb17e89><span class="vpi-sparkles" aria-hidden="true" data-v-4eb17e89></span></button><!----><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-9ca1369d data-v-7b3e138d><span id="main-nav-aria-label" class="visually-hidden" data-v-7b3e138d> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/guide/" tabindex="0" data-v-7b3e138d data-v-6500c4c4><!--[--><span data-v-6500c4c4>Guide</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/develop/" tabindex="0" data-v-7b3e138d data-v-6500c4c4><!--[--><span data-v-6500c4c4>Develop</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/contributing/" tabindex="0" data-v-7b3e138d data-v-6500c4c4><!--[--><span data-v-6500c4c4>Contributing</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/faq/" tabindex="0" data-v-7b3e138d data-v-6500c4c4><!--[--><span data-v-6500c4c4>FAQ</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7b3e138d data-v-42cb505d><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-42cb505d><span class="text" data-v-42cb505d><!----><span data-v-42cb505d>v3 (alpha)</span><span class="vpi-chevron-down text-icon" data-v-42cb505d></span></span></button><div class="menu" data-v-42cb505d><div class="VPMenu" data-v-42cb505d data-v-25a6cce8><div class="items" data-v-25a6cce8><!--[--><!--[--><div class="VPMenuLink" data-v-25a6cce8 data-v-fff73daa><a class="VPLink link" href="/en/" data-v-fff73daa><!--[--><span data-v-fff73daa>v3 (alpha)</span><!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-25a6cce8 data-v-fff73daa><a class="VPLink link" href="https://static-php.github.io/v2-docs/" data-v-fff73daa><!--[--><span data-v-fff73daa>v2</span><!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-9ca1369d data-v-c70a0580 data-v-42cb505d><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="Change language" data-v-42cb505d><span class="text" data-v-42cb505d><span class="vpi-languages option-icon" data-v-42cb505d></span><!----><span class="vpi-chevron-down text-icon" data-v-42cb505d></span></span></button><div class="menu" data-v-42cb505d><div class="VPMenu" data-v-42cb505d data-v-25a6cce8><!----><!--[--><!--[--><div class="items" data-v-c70a0580><p class="title" data-v-c70a0580>English</p><!--[--><div class="VPMenuLin
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -v</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -m</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Run a script</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> your-script.php</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Interactive mode</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -a</span></span></code></pre></div><h3 id="php-ini-search-path" tabindex="-1">php.ini search path <a class="header-anchor" href="#php-ini-search-path" aria-label="Permalink to “php.ini search path”"></a></h3><p>The static PHP cli binary searches for <code>php.ini</code> in this order:</p><ol><li>The path specified with the <code>-c /path/to/php.ini</code> command-line flag</li><li>The path set in the <code>PHP_INI_PATH</code> environment variable</li><li>The directory specified at compile time via <code>--with-config-file-path</code> (default: <code>/usr/local/etc/php</code>)</li></ol><p>Run <code>./buildroot/bin/php --ini</code> to see which ini file is actually loaded.</p><h3 id="hard-coded-ini" tabindex="-1">Hard-coded INI <a class="header-anchor" href="#hard-coded-ini" aria-label="Permalink to “Hard-coded INI”"></a></h3><p>Use <code>-I</code> at build time to bake INI settings directly into the binary, so no external <code>php.ini</code> is required:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build:php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,pcntl&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;memory_limit=4G&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;disable_functions=system,exec&quot;</span></span></code></pre></div><p>Hard-coded INI applies to the <code>cli</code>, <code>micro</code>, and <code>embed</code> SAPIs.</p><h2 id="fpm" tabindex="-1">fpm <a class="header-anchor" href="#fpm" aria-label="Permalink to “fpm”"></a></h2><p>The <code>fpm</code> SAPI (FastCGI Process Manager) is used with web servers such as Nginx or Apache for traditional web application deployments.</p><div class="warning custom-block"><p class="custom-block-title custom-block-title-default">WARNING</p><p><code>fpm</code> is not supported on Windows.</p></div><h3 id="build-1" tabindex="-1">Build <a class="header-anchor" href="#build-1" aria-label="Permalink to “Build”"></a></h3><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build:php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,openssl,curl,pdo_mysql&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-fpm</span></span></code></pre></div><p>The output is <code>buildroot/bin/php-fpm</code>.</p><p>See <a href="./cli-reference.html#sapi-selection">build:php — SAPI Selection</a> and <a href="./cli-reference.html#common-build-options">build:php — Common Build Options</a> for the full option reference.</p><h3 id="usage-1" tabindex="-1">Usage <a class="header-anchor" href="#usage-1" aria-label="Permalink to “Usage”"></a></h3><p>Copy <code>buildroot/bin/php-fpm</code> to your server and use it like a regular <code>php-fpm</code> binary:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-th
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php-fpm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -v</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Start with a specific config file</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php-fpm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/php.ini</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/php-fpm.conf</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Test config file</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/php-fpm</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -t</span></span></code></pre></div><h3 id="example-nginx-php-fpm" tabindex="-1">Example: Nginx + php-fpm <a class="header-anchor" href="#example-nginx-php-fpm" aria-label="Permalink to “Example: Nginx + php-fpm”"></a></h3><div class="language-nginx"><button title="Copy Code" class="copy"></button><span class="lang">nginx</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">server</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> listen </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">80</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> root </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">/var/www/html;</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> index </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">index.php;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> location</span><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> ~</span><span style="--shiki-light:#032F62;--shiki-dark:#DBEDFF;"> \.php$ </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> fastcgi_pass </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">127.0.0.1:9000;</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> fastcgi_param </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SCRIPT_FILENAME $document_root$fastcgi_script_name;</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> include </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">fastcgi_params;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>Example <code>php-fpm.conf</code>:</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">[global]</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">pid</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = /var/run/php-fpm.pid</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">error_log</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = /var/log/php-fpm.log</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">[www]</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">listen</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = 127.0.0.1:9000</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">pm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = dynamic</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">pm.max_children</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = 5</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">pm.start_servers</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = 2</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">pm.min_spare_servers</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = 1</span></span>
<span class="line"><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">pm.max_spare_servers</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> = 3</span></span></code></pre></div><h2 id="micro" tabindex="-1">micro <a class="header-anchor" href="#micro" aria-label="Permalink to “micro”"></a></h2><p>The <code>micro</code> SAPI is built on <a href="https://github.com/easysoft/phpmicro" target="_blank" rel="noreferrer">phpmicro</a> and produces a self-contained executable stub. With <code>spc micro:combine</code>, you can merge <code>micro.sfx</code> with your PHP code into a single portable binary that requires no PHP installation on the target machine.</p><h3 id="build-2" tabindex="-1">Build <a class="header-anchor" href="#build-2" aria-label="Permalink to “Build”"></a></h3><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build:php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,phar,openssl,curl&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-micro</span></span></code></pre></div><p>The output is <code>buildroot/bin/micro.sfx</code>.</p><p>See <a href="./cli-reference.html#sapi-selection">build:php — SAPI Selection</a>, <a href="./cli-reference.html#common-build-options">build:php — Common Build Options</a>, and <a href="./cli-reference.html#micro-options">build:php — micro Options</a> for the full option reference.</p><h3 id="packaging-an-application" tabindex="-1">Packaging an application <a class="header-anchor" href="#packaging-an-application" aria-label="Permalink to “Packaging an application”"></a></h3><p>Use <code>micro:combine</code> to bundle a PHP script or phar into a standalone executable:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Bundle a PHP script</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">echo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&lt;?php echo &#39;Hello, World!&#39; . PHP_EOL;&quot;</span><span style="--shiki-light:#c62739;--shiki-dark:#F97583;"> &gt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> hello.php</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> hello.php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --output=hello</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./hello</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Bundle a phar</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> your-app.phar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --output=your-app</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./your-app</span></span></code></pre></div><h3 id="injecting-ini-settings" tabindex="-1">Injecting INI settings <a class="header-anchor" href="#injecting-ini-settings" aria-label="Permalink to “Injecting INI settings”"></a></h3><p>INI configuration can be injected at packaging time via command-line options or an ini file:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Inject via command-line options (-I is shorthand for --with-ini-set)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> your-app.phar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --output=your-app</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;memory_limit=512M&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -I</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;curl.cainfo=/etc/ssl/certs/ca-certificates.crt&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Inject from an ini file (-N is shorthand for --with-ini-file)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> your-app.phar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --output=your-app</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -N</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/custom.ini</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title custom-block-title-default">TIP</p><p>The INI injected with <code>-I</code> here is runtime configuration appended to the <code>micro.sfx</code> file as a special structure. This is distinct from INI hard-coded at compile time using <code>-I</code> during <code>build:php</code>. Both can coexist.</p></div><h3 id="pretending-to-be-the-cli-sapi" tabindex="-1">Pretending to be the cli SAPI <a class="header-anchor" href="#pretending-to-be-the-cli-sapi" aria-label="Permalink to “Pretending to be the cli SAPI”"></a></h3><p>Some frameworks check the <code>PHP_SAPI</code> value and refuse to run outside <code>cli</code>. Since <code>micro</code>&#39;s <code>PHP_SAPI</code> is <code>micro</code> by default, you can make it report <code>cli</code> instead:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build:php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,phar&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-micro</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-micro-fake-cli</span></span></code></pre></div><h3 id="specifying-a-custom-micro-sfx-path" tabindex="-1">Specifying a custom micro.sfx path <a class="header-anchor" href="#specifying-a-custom-micro-sfx-path" aria-label="Permalink to “Specifying a custom micro.sfx path”"></a></h3><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> your-app.phar</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --output=your-app</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-micro=/path/to/your/micro.sfx</span></span></code></pre></div><h3 id="phar-path-considerations" tabindex="-1">phar path considerations <a class="header-anchor" href="#phar-path-considerations" aria-label="Permalink to “phar path considerations”"></a></h3><p>When packaging a phar, internal relative paths may behave differently than expected. See the <a href="./../develop/structure.html">Developer Guide — Phar directory issue</a> for details.</p><h2 id="embed" tabindex="-1">embed <a class="header-anchor" href="#embed" aria-label="Permalink to “embed”"></a></h2><p>The <code>embed</code> SAPI compiles PHP into a static library (<code>libphp.a</code> on Linux/macOS, <code>php8embed.lib</code> on Windows) that can be linked into C/C++ programs to run PHP code directly.</p><h3 id="build-3" tabindex="-1">Build <a class="header-anchor" href="#build-3" aria-label="Permalink to “Build”"></a></h3><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/frankenphp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> version</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Run in PHP development server mode</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/frankenphp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> php-server</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#62687b;--shiki-dark:#818e99;"># Run with a Caddyfile</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./buildroot/bin/frankenphp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> run</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --config</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/Caddyfile</span></span></code></pre></div><p>For full usage, refer to the <a href="https://frankenphp.dev/docs/" target="_blank" rel="noreferrer">FrankenPHP documentation</a>.</p><h2 id="dynamic-extension-loading" tabindex="-1">Dynamic Extension Loading <a class="header-anchor" href="#dynamic-extension-loading" aria-label="Permalink to “Dynamic Extension Loading”"></a></h2><p>Whether a static PHP binary can load extensions at runtime via <code>dl()</code> depends on how the binary was linked.</p><p><strong>macOS</strong> — The build always links dynamically against system libraries. Extensions built as <code>.so</code> files can be loaded at runtime via <code>dl()</code> or <code>php.ini</code> as usual.</p><p><strong>Linux</strong> — StaticPHP&#39;s default build target is <code>native-native-musl</code>: a fully static binary linked against musl libc. Because there is no dynamic linker available at runtime, <code>dl()</code> is disabled, the FFI extension cannot be used, and no external <code>.so</code> extensions can be loaded.</p><p>To support dynamic extension loading on Linux, set the <code>SPC_TARGET</code> environment variable before building:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SPC_TARGET</span><span style="--shiki-light:#c62739;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">native-native-gnu.2.17</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build:php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,openssl&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span></code></pre></div><p>If you installed from source, you can also set <code>SPC_TARGET=native-native-gnu.2.17</code> in <code>config/env.ini</code> to make it the default for all builds.</p><p>This uses the Zig toolchain to produce a partially static binary dynamically linked against glibc 2.17, compatible with most modern GNU/Linux distributions. No Docker and no extra cross-compilation toolchain are required. The resulting binary supports <code>dl()</code>, FFI, and loading <code>.so</code> extensions at runtime, but cannot run on musl-based systems such as Alpine Linux.</p><p><strong>Windows</strong> — PHP extensions on Windows are distributed as <code>.dll</code> files that depend on the DLLs bundled with the official dynamically-built PHP. StaticPHP produces a standalone static executable that does not include those DLLs, so dynamic extension loading is not possible on Windows. All extensions must be compiled in statically at build time.</p></div></div></main><footer class="VPDocFooter" data-v-7011f0d8 data-v-e29034c6><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-e29034c6><span class="visually-hidden" id="doc-footer-aria-label" data-v-e29034c6>Pager</span><div class="pager" data-v-e29034c6><a class="VPLink link pager-link prev" href="/en/guide/first-build.html" data-v-e29034c6><!--[--><span class="desc" data-v-e29034c6>Previous page</span><span class="title" data-v-e29034c6>First Build</span><!--]--></a></div><div class="pager" data-v-e29034c6><a class="VPLink link pager-link next" href="/en/guide/cli-reference.html" data-v-e29034c6><!--[--><span class="desc" data-v-e29034c6>Next page</span><span class="title" data-v-e29034c6>CLI Reference</span><!--]--
<script>window.__VP_HASH_MAP__=JSON.parse("{\"deps-craft-yml.md\":\"BlUAUDy4\",\"en_contributing_index.md\":\"DJrK0rwl\",\"en_develop_artifact-model.md\":\"CSsy1IGq\",\"en_develop_build-lifecycle.md\":\"DAZqcB7z\",\"en_develop_craft-yml.md\":\"KSoZofRA\",\"en_develop_doctor-module.md\":\"ByvES-_A\",\"en_develop_extending_annotations.md\":\"UKL7B7B3\",\"en_develop_extending_custom-artifact.md\":\"DotD8ITd\",\"en_develop_extending_dependency-injection.md\":\"CyyHOkvH\",\"en_develop_extending_index.md\":\"B2xj8d9p\",\"en_develop_extending_lifecycle-hooks.md\":\"6uwWcfAD\",\"en_develop_extending_package-classes.md\":\"y3Xf7UZ4\",\"en_develop_index.md\":\"BITZJqcR\",\"en_develop_package-model.md\":\"CMZBu01x\",\"en_develop_php-src-changes.md\":\"Cc0fC8cE\",\"en_develop_registry.md\":\"BsjJNDQv\",\"en_develop_structure.md\":\"D8gP8oQJ\",\"en_develop_system-build-tools.md\":\"CUw5wQ4E\",\"en_faq_index.md\":\"BvIAh2aW\",\"en_guide_cli-generator.md\":\"C6SB8xhE\",\"en_guide_cli-reference.md\":\"D7EY77fp\",\"en_guide_deps-map.md\":\"DKgvqXtD\",\"en_guide_env-vars.md\":\"BgjYKJG9\",\"en_guide_extension-notes.md\":\"B3shjkUU\",\"en_guide_extensions.md\":\"ATwZq3HB\",\"en_guide_first-build.md\":\"INdBGOsG\",\"en_guide_index.md\":\"z0D1Gcrs\",\"en_guide_installation.md\":\"BV9Ks-lX\",\"en_guide_migrate-from-v2.md\":\"CUFkYufx\",\"en_guide_sapi-reference.md\":\"p2zEyiLe\",\"en_guide_troubleshooting.md\":\"DVi8H9ZX\",\"en_index.md\":\"D-9tNbNs\",\"index.md\":\"TfAAAF_x\",\"zh_contributing_index.md\":\"8SUl40-w\",\"zh_develop_artifact-model.md\":\"CrLRSeeY\",\"zh_develop_build-lifecycle.md\":\"DLh_YUAK\",\"zh_develop_craft-yml.md\":\"uyL3P4FG\",\"zh_develop_doctor-module.md\":\"B-KVjOyS\",\"zh_develop_extending_annotations.md\":\"Dcz6J_X-\",\"zh_develop_extending_custom-artifact.md\":\"BoYCxDEr\",\"zh_develop_extending_dependency-injection.md\":\"BKeBJfDY\",\"zh_develop_extending_index.md\":\"B7wWMbKy\",\"zh_develop_extending_lifecycle-hooks.md\":\"CG51Rugr\",\"zh_develop_extending_package-classes.md\":\"DBU2hT9_\",\"zh_develop_index.md\":\"CrUwzvi2\",\"zh_develop_package-model.md\":\"DDw9ZCCd\",\"zh_develop_php-src-changes.md\":\"artDuYna\",\"zh_develop_registry.md\":\"ChqnXzVM\",\"zh_develop_structure.md\":\"BivWsi6C\",\"zh_develop_system-build-tools.md\":\"BLdfbezU\",\"zh_faq_index.md\":\"ypwV8ySx\",\"zh_guide_cli-generator.md\":\"BuKsNlwB\",\"zh_guide_cli-reference.md\":\"LVzdkmu2\",\"zh_guide_deps-map.md\":\"9-QWHshB\",\"zh_guide_env-vars.md\":\"D2oUaqNR\",\"zh_guide_extension-notes.md\":\"D9lGXhKW\",\"zh_guide_extensions.md\":\"CNtRfejb\",\"zh_guide_first-build.md\":\"DSwF9CHy\",\"zh_guide_index.md\":\"DR1hBcxc\",\"zh_guide_installation.md\":\"CWZRSBwL\",\"zh_guide_migrate-from-v2.md\":\"Dp7VZbGT\",\"zh_guide_sapi-reference.md\":\"TjYI_FdR\",\"zh_guide_troubleshooting.md\":\"CJ6N_2fk\",\"zh_index.md\":\"BXvgifjq\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"StaticPHP\",\"description\":\"A powerful tool designed for building portable executables including PHP, extensions, and more.\",\"base\":\"/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"logo\":\"/images/static-php_nobg.png\",\"nav\":[],\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/crazywhalecc/static-php-cli\"}],\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"},\"externalLinkIcon\":true,\"search\":{\"provider\":\"algolia\",\"options\":{\"appId\":\"IHJHUB1SF1\",\"apiKey\":\"8266d31cc2ffbd0e059f1c6e5bdaf8fc\",\"indexName\":\"static-php docs\",\"askAi\":{\"assistantId\":\"b72369b2-60a5-461d-902c-5c18d8c05902\",\"agentStudio\":true,\"sidePanel\":true}}}},\"locales\":{\"en\":{\"label\":\"English\",\"lang\":\"en\",\"themeConfig\":{\"nav\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Develop\",\"link\":\"/en/develop/\"},{\"text\":\"Contributing\",\"link\":\"/en/contributing/\"},{\"text\":\"FAQ\",\"link\":\"/en/faq/\"},{\"text\":\"v3 (alpha)\",\"items\":[{\"text\":\"v3 (alpha)\",\"link\":\"/en/\
</body>
</html>