static-php-cli/en/guide/build-on-windows.html
2024-08-11 04:32:02 +00:00

46 lines
40 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Build on Windows | static-php-cli</title>
<meta name="description" content="Build single static PHP binary, with PHP project together, with popular extensions included.">
<meta name="generator" content="VitePress v1.2.3">
<link rel="preload stylesheet" href="/assets/style.B7QwpTn2.css" as="style">
<script type="module" src="/assets/app.DAnd8ZqT.js"></script>
<link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/assets/chunks/framework.CszIUXhs.js">
<link rel="modulepreload" href="/assets/chunks/theme.Yd2LEGgK.js">
<link rel="modulepreload" href="/assets/en_guide_build-on-windows.md.Bw1buXoR.lean.js">
<script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a: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-5d98c3a5><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0f60ec36></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0f60ec36> Skip to content </a><!--]--><!----><header class="VPNav" data-v-5d98c3a5 data-v-ae24b3ad><div class="VPNavBar has-sidebar top" data-v-ae24b3ad data-v-ccf7ddec><div class="wrapper" data-v-ccf7ddec><div class="container" data-v-ccf7ddec><div class="title" data-v-ccf7ddec><div class="VPNavBarTitle has-sidebar" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/en/" data-v-ab179fa1><!--[--><!--]--><!----><span data-v-ab179fa1>static-php-cli</span><!--[--><!--]--></a></div></div><div class="content" data-v-ccf7ddec><div class="content-body" data-v-ccf7ddec><!--[--><!--]--><div class="VPNavBarSearch search" data-v-ccf7ddec><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-ccf7ddec data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>Main Navigation</span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/guide/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Guide</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/develop/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Advanced</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/contributing/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>Contributing</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/faq/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>FAQ</span><!--]--></a><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-ccf7ddec data-v-88af2de4 data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="Change language" data-v-b6c34ac9><span class="text" data-v-b6c34ac9><span class="vpi-languages option-icon" data-v-b6c34ac9></span><!----><span class="vpi-chevron-down text-icon" data-v-b6c34ac9></span></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-e7ea1737><!----><!--[--><!--[--><div class="items" data-v-88af2de4><p class="title" data-v-88af2de4>English</p><!--[--><div class="VPMenuLink" data-v-88af2de4 data-v-43f1e123><a class="VPLink link" href="/zh/guide/build-on-windows.html" data-v-43f1e123><!--[-->简体中文<!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-ccf7ddec data-v-e6aabb21><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-e6aabb21 data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-ccf7ddec data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-ccf7ddec data-v-d0bd9dde data-v-b6c34ac9><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-b6c34ac9><span class="vpi-more-horizontal icon" data-v-b6c34ac9></span></button><div class="menu" data-v-b6c34ac9><div class="VPMenu" data-v-b6c34ac9 data-v-e7ea1737><!----><!--[--><!--[--><div class="group translations" data-v-d0bd9dde><p class="trans-title" data-v-d0bd9dde>English</p><!--[--><div class="VPMenuLink" data-v-d0bd9dde data-v-43f1e123><a class="VPLink link" href="/zh/guide/build-on-windows.html" data-v-43f1e123><!--[-->简体中文<!--]--></a></div><!--]--></div><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p class="label" data-v-d0bd9dde>Appearance</p><div class="appearance-action" data-v-d0bd9dde><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-d0bd9dde data-v-d1f28634 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-d1f28634></span><span class="vpi-moon moon" data-v-d1f28634></span><!--]--></span></span></button></div></div></div><div class="group" data-v-d0bd9dde><div class="item social-links" data-v-d0bd9dde><div class="VPSocialLinks social-links-list" data-v-d0bd9dde data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-eee4e7cb><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-ccf7ddec data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><div class="divider" data-v-ccf7ddec><div class="divider-line" data-v-ccf7ddec></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-5d98c3a5 data-v-a6f0e41e><div class="container" data-v-a6f0e41e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a6f0e41e><span class="vpi-align-left menu-icon" data-v-a6f0e41e></span><span class="menu-text" data-v-a6f0e41e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a6f0e41e data-v-17a5e62e><button data-v-17a5e62e>Return to top</button><!----></div></div></div><aside class="VPSidebar" data-v-5d98c3a5 data-v-575e6a36><div class="curtain" data-v-575e6a36></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-575e6a36><span class="visually-hidden" id="sidebar-aria-label" data-v-575e6a36> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0" data-v-575e6a36 data-v-b8d55f3b><div class="item" role="button" tabindex="0" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><h2 class="text" data-v-b8d55f3b>Guide</h2><!----></div><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Guide</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/action-build.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Actions Build</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/manual-build.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Manual Build</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/extensions.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Extension List</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/extension-notes.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Extension Notes</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/cli-generator.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Command Generator</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 collapsible collapsed is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/env-vars.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Environment Variables</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-575e6a36><section class="VPSidebarItem level-0 has-active" data-v-575e6a36 data-v-b8d55f3b><!----><div class="items" data-v-b8d55f3b><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/troubleshooting.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Troubleshooting</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b8d55f3b data-v-b8d55f3b><div class="item" data-v-b8d55f3b><div class="indicator" data-v-b8d55f3b></div><a class="VPLink link link" href="/en/guide/build-on-windows.html" data-v-b8d55f3b><!--[--><p class="text" data-v-b8d55f3b>Build on Windows</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-5d98c3a5 data-v-1428d186><div class="VPDoc has-sidebar has-aside" data-v-1428d186 data-v-39a288b8><!--[--><!--]--><div class="container" data-v-39a288b8><div class="aside" data-v-39a288b8><div class="aside-curtain" data-v-39a288b8></div><div class="aside-container" data-v-39a288b8><div class="aside-content" data-v-39a288b8><div class="VPDocAside" data-v-39a288b8 data-v-3f215769><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-3f215769 data-v-a5bbad30><div class="content" data-v-a5bbad30><div class="outline-marker" data-v-a5bbad30></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-a5bbad30>On this page</div><ul class="VPDocOutlineItem root" data-v-a5bbad30 data-v-b933a997><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-39a288b8><div class="content-container" data-v-39a288b8><!--[--><!--]--><main class="main" data-v-39a288b8><div style="position:relative;" class="vp-doc _en_guide_build-on-windows" data-v-39a288b8><div><h1 id="build-on-windows" tabindex="-1">Build on Windows <a class="header-anchor" href="#build-on-windows" aria-label="Permalink to &quot;Build on Windows&quot;"></a></h1><p>Because the Windows system is an NT kernel, the compilation tools and operating system interfaces used by Unix-like operating systems are almost completely different, so the build process on Windows will be slightly different from that of Unix systems.</p><h2 id="github-actions-build" tabindex="-1">GitHub Actions Build <a class="header-anchor" href="#github-actions-build" aria-label="Permalink to &quot;GitHub Actions Build&quot;"></a></h2><p>Building the Windows version of static-php from Actions is now supported. Like Linux and macOS, you need to Fork the static-php-cli repository to your GitHub account first, then you can enter <a href="./extensions.html">Extension List</a> to select the extension to be compiled, and then go to your own <code>CI on Windows</code> select the PHP version, fill in the extension list (comma separated), and click Run.</p><p>If you&#39;re going to develop or build locally, please read on.</p><h2 id="requirements" tabindex="-1">Requirements <a class="header-anchor" href="#requirements" aria-label="Permalink to &quot;Requirements&quot;"></a></h2><p>The tools required to build static PHP on Windows are the same as PHP&#39;s official Windows build tools. You can read <a href="https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2" target="_blank" rel="noreferrer">Official Documentation</a>.</p><p>To sum up, you need the following environment and tools:</p><ul><li>Windows 10/11 (requires build 17063 or later)</li><li>Visual Studio 2019/2022 (recommended 2022)</li><li>C++ desktop development for Visual Studio</li><li>Git for Windows</li><li><a href="https://github.com/php/php-sdk-binary-tools" target="_blank" rel="noreferrer">php-sdk-binary-tools</a> (can be installed automatically using doctor)</li><li>strawberry-perl (can be installed automatically using doctor)</li><li>nasm (can be installed automatically using doctor)</li></ul><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>The construction of static-php-cli on Windows refers to using MSVC to build PHP and is not based on MinGW, Cygwin, WSL and other environments.</p><p>If you prefer to use WSL, please refer to the chapter on Building on Linux.</p></div><p>After installing Visual Studio and selecting the C++ desktop development workload, you may download about 8GB of compilation tools, and the download speed depends on your network conditions.</p><h3 id="install-git" tabindex="-1">Install Git <a class="header-anchor" href="#install-git" aria-label="Permalink to &quot;Install Git&quot;"></a></h3><p>Git for Windows can be downloaded and installed from <a href="https://git-scm.com/download/win" target="_blank" rel="noreferrer">here</a> <code>Standalone Installer 64-bit</code> version, installed in the default location (<code>C:\Program Files\Git\</code>). If you don&#39;t want to download and install manually, you can also use Visual Studio Installer and check Git in the <strong>Individual component</strong> tab.</p><h3 id="prepare-static-php-cli" tabindex="-1">Prepare static-php-cli <a class="header-anchor" href="#prepare-static-php-cli" aria-label="Permalink to &quot;Prepare static-php-cli&quot;"></a></h3><p>Downloading the static-php-cli project is very simple, just use git clone. It is recommended to place the project in <code>C:\spc-build\</code> or a similar directory. It is best <strong>not to have spaces in the path</strong>.</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mkdir</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;C:\spc-build&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> C:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">pc-build</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/crazywhalecc/static-php-cli.git</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> static-php-cli</span></span></code></pre></div><p>It is a bit strange that static-php-cli itself requires a PHP environment, but now you can quickly install the PHP environment through a script. Generally, your computer will not have the Windows version of PHP installed, so we recommend that you use <code>bin/setup-runtime</code> directly after downloading static-php-cli to install PHP and Composer in the current directory.</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Install PHP and Composer to the ./runtime/ directory</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/setup-runtime</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># After installation, if you need to use PHP and Composer in global commands, </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># use the following command to add the runtime/ directory to PATH</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/setup-runtime</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -action</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> add-path</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Delete the runtime/ directory in PATH</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/setup-runtime</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -action</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> remove-path</span></span></code></pre></div><h3 id="install-other-tools-automatic" tabindex="-1">Install other Tools (automatic) <a class="header-anchor" href="#install-other-tools-automatic" aria-label="Permalink to &quot;Install other Tools (automatic)&quot;"></a></h3><p>For <code>php-sdk-binary-tools</code>, <code>strawberry-perl</code>, and <code>nasm</code>, we recommend that you directly use the command <code>bin/spc doctor</code> to check and install them.</p><p>If doctor successfully installs automatically, please <strong>skip</strong> the steps below to manually install the above tools.</p><p>But if the automatic installation fails, please refer to the manual installation method below.</p><h3 id="install-php-sdk-binary-tools-manual" tabindex="-1">Install php-sdk-binary-tools (manual) <a class="header-anchor" href="#install-php-sdk-binary-tools-manual" aria-label="Permalink to &quot;Install php-sdk-binary-tools (manual)&quot;"></a></h3><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> C:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">pc-build</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\s</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">tatic-php-cli</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/php/php-sdk-binary-tools.git</span></span></code></pre></div><blockquote><p>You can also set the global variable <code>PHP_SDK_PATH</code> in Windows settings and clone the project to the path corresponding to the variable. Under normal circumstances, you don&#39;t need to change it.</p></blockquote><h3 id="install-strawberry-perl-manual" tabindex="-1">Install strawberry-perl (manual) <a class="header-anchor" href="#install-strawberry-perl-manual" aria-label="Permalink to &quot;Install strawberry-perl (manual)&quot;"></a></h3><blockquote><p>If you don&#39;t need to compile the openssl extension, you don&#39;t need to install perl.</p></blockquote><ol><li>Download the latest version of strawberry-perl from <a href="https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/" target="_blank" rel="noreferrer">GitHub</a>.</li><li>Install to the <code>C:\spc-build\static-php-cli\pkgroot\perl\</code> directory.</li></ol><blockquote><p>You can download the <code>-portable</code> version and extract it directly to the above directory. The last <code>perl.exe</code> should be located at <code>C:\spc-build\static-php-cli\pkgroot\perl\perl\bin\perl.exe</code>.</p></blockquote><h3 id="install-nasm-manual" tabindex="-1">Install nasm (manual) <a class="header-anchor" href="#install-nasm-manual" aria-label="Permalink to &quot;Install nasm (manual)&quot;"></a></h3><blockquote><p>If you don&#39;t need to compile openssl extension, you don&#39;t need to install nasm.</p></blockquote><ol><li>Download the nasm tool (x64) from <a href="https://www.nasm.us/pub/nasm/releasebuilds/" target="_blank" rel="noreferrer">official website</a>.</li><li>Place <code>nasm.exe</code> and <code>ndisasm.exe</code> in the <code>C:\spc-build\static-php-cli\php-sdk-binary-tools\bin\</code> directory.</li></ol><h2 id="download-required-sources" tabindex="-1">Download required sources <a class="header-anchor" href="#download-required-sources" aria-label="Permalink to &quot;Download required sources&quot;"></a></h2><p>Same as <a href="./manual-build.html#command-download">Manual build - Download</a></p><h2 id="build-php" tabindex="-1">Build PHP <a class="header-anchor" href="#build-php" aria-label="Permalink to &quot;Build PHP&quot;"></a></h2><p>Use the build command to start building the static php binary. Before executing the <code>bin/spc build</code> command, be sure to use the <code>download</code> command to download sources. It is recommended to use <code>doctor</code> to check the environment.</p><h3 id="build-sapi" tabindex="-1">Build SAPI <a class="header-anchor" href="#build-sapi" aria-label="Permalink to &quot;Build SAPI&quot;"></a></h3><p>You need to go to <a href="./extensions.html">Extension List</a> or <a href="./cli-generator.html">Command Generator</a> to select the extension you want to add, and then use the command <code>bin/spc build</code> to compile. You need to specify targets, choose from the following parameters (at least one):</p><ul><li><code>--build-cli</code>: Build a cli sapi (command line interface, which can execute PHP code on the command line)</li><li><code>--build-micro</code>: Build a micro sapi (used to build a standalone executable binary containing PHP code)</li></ul><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Compile PHP with bcmath,openssl,zlib extensions, the compilation target is cli</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,openssl,zlib&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Compile PHP with phar,curl,posix,pcntl,tokenizer extensions, compile target is micro and cli</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;bcmath,openssl,zlib&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-micro</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span></code></pre></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>In Windows, it is best to use double quotes to wrap parameters containing commas, such as <code>&quot;bcmath,openssl,mbstring&quot;</code>.</p></div><h3 id="debug" tabindex="-1">Debug <a class="header-anchor" href="#debug" aria-label="Permalink to &quot;Debug&quot;"></a></h3><p>If you encounter problems during the compilation process, or want to view each executing shell command, you can use <code>--debug</code> to enable debug mode and view all terminal logs:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;openssl&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --debug</span></span></code></pre></div><h3 id="build-options" tabindex="-1">Build Options <a class="header-anchor" href="#build-options" aria-label="Permalink to &quot;Build Options&quot;"></a></h3><p>During the compilation process, in some special cases, the compiler and the content of the compilation directory need to be intervened. You can try to use the following commands:</p><ul><li><code>--with-clean</code>: clean up old make files before compiling PHP</li><li><code>--enable-zts</code>: Make compiled PHP thread-safe version (default is NTS version)</li><li><code>--with-libs=XXX,YYY</code>: Compile the specified dependent library before compiling PHP, and activate some extension optional functions</li><li><code>-I xxx=yyy</code>: Hard compile INI options into PHP before compiling (support multiple options, alias is <code>--with-hardcoded-ini</code>)</li><li><code>--with-micro-fake-cli</code>: When compiling micro, let micro&#39;s <code>PHP_SAPI</code> pretend to be <code>cli</code> (for compatibility with some programs that check <code>PHP_SAPI</code>)</li><li><code>--disable-opcache-jit</code>: Disable opcache jit (enabled by default)</li><li><code>--without-micro-ext-test</code>: After building micro.sfx, do not test the running results of different extensions in micro.sfx</li><li><code>--with-suggested-exts</code>: Add <code>ext-suggests</code> as dependencies when compiling</li><li><code>--with-suggested-libs</code>: Add <code>lib-suggests</code> as dependencies when compiling</li><li><code>--with-upx-pack</code>: Use UPX to reduce the size of the binary file after compilation (you need to use <code>bin/spc install-pkg upx</code> to install upx first)</li><li><code>--with-micro-logo=XXX.ico</code>: Customize the icon of the <code>exe</code> executable file after customizing the micro build (in the format of <code>.ico</code>)</li></ul><p>Here is a simple example where we preset a larger <code>memory_limit</code> and disable the <code>system</code> function:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</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 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&quot;</span></span></code></pre></div><p>Another example: Customize our hello-world.exe program logo:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;ffi,bcmath&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-micro</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-micro-logo=mylogo.ico</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --debug</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/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>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Then we got `my-app.exe` with custom logo!</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">my-app.exe</span></span></code></pre></div><h2 id="use-php-exe" tabindex="-1">Use php.exe <a class="header-anchor" href="#use-php-exe" aria-label="Permalink to &quot;Use php.exe&quot;"></a></h2><p>After php.exe is compiled, it is located in the <code>buildroot\bin\</code> directory. You can copy it to any location for use.</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">\</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -v</span></span></code></pre></div><h2 id="use-micro-sfx" tabindex="-1">Use micro.sfx <a class="header-anchor" href="#use-micro-sfx" aria-label="Permalink to &quot;Use micro.sfx&quot;"></a></h2><blockquote><p>phpmicro is a SelF-extracted eXecutable SAPI module, provided by <a href="https://github.com/dixyes/phpmicro" target="_blank" rel="noreferrer">phpmicro</a> project. But this project is using a <a href="https://github.com/static-php/phpmicro" target="_blank" rel="noreferrer">fork</a> of phpmicro, because we need to add some features to it. It can put php runtime and your source code together.</p></blockquote><p>The final compilation result will output a file named <code>./micro.sfx</code>, which needs to be used with your PHP source code like <code>code.php</code>. This file will be located in the path <code>buildroot/bin/micro.sfx</code>.</p><p>Prepare your project source code, which can be a single PHP file or a Phar file, for use.</p><blockquote><p>If you want to combine phar files, you must add <code>phar</code> extension when compiling!</p></blockquote><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># code.php &quot;&lt;?php echo &#39;Hello world&#39; . PHP_EOL;&quot;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> micro:combine</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> code.php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -O</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> my-app.exe</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Run it!!! Copy it to another computer!!!</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./my-app.exe</span></span></code></pre></div><p>If you package a PHAR file, just replace <code>code.php</code> with the phar file path. You can use <a href="https://github.com/box-project/box" target="_blank" rel="noreferrer">box-project/box</a> to package your CLI project as Phar, It is then combined with phpmicro to produce a standalone executable binary.</p><p>For more details on the <code>micro:combine</code> command, refer to <a href="./manual-build.html">command</a> on Unix systems.</p></div></div></main><footer class="VPDocFooter" data-v-39a288b8 data-v-d4a0bba5><!--[--><!--]--><!----><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-d4a0bba5><span class="visually-hidden" id="doc-footer-aria-label" data-v-d4a0bba5>Pager</span><div class="pager" data-v-d4a0bba5><a class="VPLink link pager-link prev" href="/en/guide/troubleshooting.html" data-v-d4a0bba5><!--[--><span class="desc" data-v-d4a0bba5>Previous page</span><span class="title" data-v-d4a0bba5>Troubleshooting</span><!--]--></a></div><div class="pager" data-v-d4a0bba5><!----></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-5d98c3a5 data-v-e315a0ad><div class="container" data-v-e315a0ad><p class="message" data-v-e315a0ad>Released under the MIT License.</p><p class="copyright" data-v-e315a0ad>Copyright © 2023-present crazywhalecc</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"en_guide_cli-generator.md\":\"BZhpYvNU\",\"en_guide_extensions.md\":\"BtMDj8Bu\",\"en_guide_env-vars.md\":\"XRLVeMgw\",\"en_guide_extension-notes.md\":\"C-SzmSnl\",\"en_guide_action-build.md\":\"DqfXKtKF\",\"zh_guide_cli-generator.md\":\"fxBRrvQl\",\"zh_guide_env-vars.md\":\"Dn5AS_wq\",\"en_develop_index.md\":\"BqNiKnHj\",\"zh_guide_extension-notes.md\":\"BI7HOrtL\",\"en_develop_php-src-changes.md\":\"Dw_q8s3t\",\"zh_develop_structure.md\":\"DDUlE6Vc\",\"zh_develop_php-src-changes.md\":\"C7L9rEms\",\"en_develop_doctor-module.md\":\"M_P38WuA\",\"zh_develop_source-module.md\":\"ByssbQZ9\",\"zh_develop_index.md\":\"CISWAEXj\",\"extensions.md\":\"2KrBccsz\",\"index.md\":\"DDaDbFm-\",\"zh_contributing_index.md\":\"BgLPhRbJ\",\"en_guide_index.md\":\"DzPC1rL-\",\"en_faq_index.md\":\"DM_hczmb\",\"zh_develop_doctor-module.md\":\"CPRdzud3\",\"en_develop_source-module.md\":\"BvLG6ZYy\",\"zh_develop_system-build-tools.md\":\"DvA9SnOG\",\"zh_faq_index.md\":\"Bs3v_2I2\",\"zh_index.md\":\"Bu-me8xZ\",\"zh_guide_manual-build.md\":\"DuFqT3ee\",\"en_develop_structure.md\":\"Bam0WW0K\",\"zh_guide_index.md\":\"D0Jfo4Dz\",\"zh_guide_build-on-windows.md\":\"C1RFP4Q6\",\"zh_guide_action-build.md\":\"BQOsJgGT\",\"en_contributing_index.md\":\"0xRtVBv6\",\"en_develop_system-build-tools.md\":\"Ds5Kgdf6\",\"en_guide_troubleshooting.md\":\"BZNNttUZ\",\"en_index.md\":\"B7rqxnyF\",\"extension-notes.md\":\"CYTuu5Xm\",\"en_guide_build-on-windows.md\":\"Bw1buXoR\",\"zh_guide_extensions.md\":\"BHyfzh9r\",\"zh_guide_troubleshooting.md\":\"CSXAWaMN\",\"en_guide_manual-build.md\":\"Bn941fl8\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"static-php-cli\",\"description\":\"Build single static PHP binary, with PHP project together, with popular extensions included.\",\"base\":\"/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"nav\":[],\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/crazywhalecc/static-php-cli\"}]},\"locales\":{\"en\":{\"label\":\"English\",\"lang\":\"en\",\"themeConfig\":{\"nav\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Advanced\",\"link\":\"/en/develop/\"},{\"text\":\"Contributing\",\"link\":\"/en/contributing/\"},{\"text\":\"FAQ\",\"link\":\"/en/faq/\"}],\"sidebar\":{\"/en/guide/\":[{\"text\":\"Guide\",\"items\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Actions Build\",\"link\":\"/en/guide/action-build\"},{\"text\":\"Manual Build\",\"link\":\"/en/guide/manual-build\"},{\"text\":\"Extension List\",\"link\":\"/en/guide/extensions\"},{\"text\":\"Extension Notes\",\"link\":\"/en/guide/extension-notes\"},{\"text\":\"Command Generator\",\"link\":\"/en/guide/cli-generator\"},{\"text\":\"Environment Variables\",\"link\":\"/en/guide/env-vars\",\"collapsed\":true}]},{\"items\":[{\"text\":\"Troubleshooting\",\"link\":\"/en/guide/troubleshooting\"},{\"text\":\"Build on Windows\",\"link\":\"/en/guide/build-on-windows\"}]}],\"/en/develop/\":[{\"text\":\"Development\",\"items\":[{\"text\":\"Get Started\",\"link\":\"/en/develop/\"},{\"text\":\"Project Structure\",\"link\":\"/en/develop/structure\"},{\"text\":\"PHP Source Modification\",\"link\":\"/en/develop/php-src-changes\"}]},{\"text\":\"Module\",\"items\":[{\"text\":\"Doctor \",\"link\":\"/en/develop/doctor-module\"},{\"text\":\"Source\",\"link\":\"/en/develop/source-module\"}]},{\"text\":\"Extra\",\"items\":[{\"text\":\"Compilation Tools\",\"link\":\"/en/develop/system-build-tools\"}]}],\"/en/contributing/\":[{\"text\":\"Contributing\",\"items\":[{\"text\":\"Contributing\",\"link\":\"/en/contributing/\"}]}]},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"}}},\"zh\":{\"label\":\"简体中文\",\"lang\":\"zh\",\"themeConfig\":{\"nav\":[{\"text\":\"构建指南\",\"link\":\"/zh/guide/\"},{\"text\":\"进阶\",\"link\":\"/zh/develop/\"},{\"text\":\"贡献\",\"link\":\"/zh/contributing/\"},{\"text\":\"FAQ\",\"link\":\"/zh/faq/\"}],\"sidebar\":{\"/zh/guide/\":[{\"text\":\"构建指南\",\"items\":[{\"text\":\"指南\",\"link\":\"/zh/guide/\"},{\"text\":\"Actions 构建\",\"link\":\"/zh/guide/action-build\"},{\"text\":\"本地构建\",\"link\":\"/zh/guide/manual-build\"},{\"text\":\"扩展列表\",\"link\":\"/zh/guide/extensions\"},{\"text\":\"扩展注意事项\",\"link\":\"/zh/guide/extension-notes\"},{\"text\":\"编译命令生成器\",\"link\":\"/zh/guide/cli-generator\"},{\"text\":\"环境变量列表\",\"link\":\"/zh/guide/env-vars\"}]},{\"items\":[{\"text\":\"故障排除\",\"link\":\"/zh/guide/troubleshooting\"},{\"text\":\"在 Windows 上构建\",\"link\":\"/zh/guide/build-on-windows\"}]}],\"/zh/develop/\":[{\"text\":\"开发指南\",\"items\":[{\"text\":\"开发简介\",\"link\":\"/zh/develop/\"},{\"text\":\"项目结构简介\",\"link\":\"/zh/develop/structure\"},{\"text\":\"对 PHP 源码的修改\",\"link\":\"/zh/develop/php-src-changes\"}]},{\"text\":\"模块\",\"items\":[{\"text\":\"Doctor 环境检查工具\",\"link\":\"/zh/develop/doctor-module\"},{\"text\":\"资源模块\",\"link\":\"/zh/develop/source-module\"}]},{\"text\":\"其他\",\"items\":[{\"text\":\"系统编译工具\",\"link\":\"/zh/develop/system-build-tools\"}]}],\"/zh/contributing/\":[{\"text\":\"贡献指南\",\"items\":[{\"text\":\"贡献指南\",\"link\":\"/zh/contributing/\"}]}]},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"}}}},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
</body>
</html>