Files
static-php-cli/assets/zh_guide_installation.md.Ap2snxXu.js
2026-07-04 07:43:21 +00:00

10 lines
17 KiB
JavaScript
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.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{_ as s,c as a,o as t,aj as e}from"./chunks/framework.C2AwuPrQ.js";const o=JSON.parse('{"title":"安装 StaticPHP","description":"","frontmatter":{},"headers":[],"relativePath":"zh/guide/installation.md","filePath":"zh/guide/installation.md"}'),l={name:"zh/guide/installation.md"};function h(n,i,p,k,d,r){return t(),a("div",null,[...i[0]||(i[0]=[e(`<h1 id="安装-staticphp" tabindex="-1">安装 StaticPHP <a class="header-anchor" href="#安装-staticphp" aria-label="Permalink to “安装 StaticPHP”"></a></h1><h2 id="系统要求" tabindex="-1">系统要求 <a class="header-anchor" href="#系统要求" aria-label="Permalink to “系统要求”"></a></h2><table tabindex="0"><thead><tr><th>平台</th><th>架构</th><th>说明</th></tr></thead><tbody><tr><td>Linux</td><td>x86_64、aarch64</td><td>支持主流发行版Alpine、Debian/Ubuntu、RHEL/CentOS 等)</td></tr><tr><td>macOS</td><td>x86_64 (Intel)、arm64 (Apple Silicon)</td><td>需要 macOS 12 或更高版本</td></tr><tr><td>Windows</td><td>x86_64</td><td>需要 Windows 10 Build 17063 或更高版本</td></tr></tbody></table><div class="tip custom-block"><p class="custom-block-title custom-block-title-default">TIP</p><p>Linux 下glibc 环境Debian、Ubuntu、Arch 等)和 musl 环境Alpine均受支持。 <code>doctor</code> 命令会自动检测当前环境并在必要时引导安装合适的工具链。</p></div><p>StaticPHP 有多种安装方式,选择适合你的场景:</p><table tabindex="0"><thead><tr><th>方式</th><th>适合谁</th></tr></thead><tbody><tr><td>预编译二进制</td><td>大多数用户,直接下载开箱即用</td></tr><tr><td>从源码安装</td><td>参与开发、或需要修改核心构建逻辑的开发者</td></tr><tr><td>Vendor 模式</td><td>在已有 PHP 项目中集成 StaticPHP 能力</td></tr></tbody></table><h2 id="预编译二进制" tabindex="-1">预编译二进制 <a class="header-anchor" href="#预编译二进制" aria-label="Permalink to “预编译二进制”"></a></h2><p>spc 无须任何依赖,下载即可运行,支持 Linux、macOS 和 Windows。</p><blockquote><p>spc 本身是由 StaticPHP 构建的静态 PHP 二进制,幽默地说:我们用 StaticPHP 构建了 StaticPHP 的构建工具。</p></blockquote><div class="vp-code-group"><div class="tabs"><input type="radio" name="group-113" id="tab-114" checked><label data-title="Linux x86_64" for="tab-114">Linux x86_64</label><input type="radio" name="group-113" id="tab-115"><label data-title="Linux arm64" for="tab-115">Linux arm64</label><input type="radio" name="group-113" id="tab-116"><label data-title="macOS x86_64" for="tab-116">macOS x86_64</label><input type="radio" name="group-113" id="tab-117"><label data-title="macOS arm64" for="tab-117">macOS arm64</label><input type="radio" name="group-113" id="tab-118"><label data-title="Windows x86_64" for="tab-118">Windows x86_64</label></div><div class="blocks"><div class="language-shell active"><button title="Copy Code" class="copy"></button><span class="lang">shell</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;">curl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -#fSL</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-x86_64</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span></span></code></pre></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</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;">curl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -#fSL</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/v3/spc-bin/nightly/spc-linux-aarch64</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span></span></code></pre></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</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;">curl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -#fSL</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-x86_64</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span></span></code></pre></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</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;">curl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -#fSL</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://dl.static-php.dev/v3/spc-bin/nightly/spc-macos-aarch64</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span></span></code></pre></div><div class="language-powershell"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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:#005CC5;--shiki-dark:#79B8FF;">curl.exe</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">#fSL https:</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">//</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">dl.</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">static-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">php.dev</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">v3</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">spc</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">bin</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">nightly</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">spc-windows-x86_64.exe</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> -</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">o </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">spc.exe</span></span></code></pre></div></div></div><p>*nix 系统下载完成后需要赋予可执行权限:</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;">chmod</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> +x</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> spc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./spc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --version</span></span></code></pre></div><h2 id="从源码安装" tabindex="-1">从源码安装 <a class="header-anchor" href="#从源码安装" aria-label="Permalink to “从源码安装”"></a></h2><p>适合想参与开发、或需要修改核心注册表和构建脚本的开发者。需要系统已安装 PHP &gt;= 8.4、Composer以及 <code>mbstring,posix,pcntl,iconv,phar,zlib</code> 扩展。</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;">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 style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --branch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> v3</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>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">composer</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span></span></code></pre></div><p>如果系统还没有 PHP 和 Composer可以用内置脚本一键安装运行环境</p><div class="vp-code-group"><div class="tabs"><input type="radio" name="group-134" id="tab-135" checked><label data-title="Linux / macOS" for="tab-135">Linux / macOS</label><input type="radio" name="group-134" id="tab-136"><label data-title="Windows" for="tab-136">Windows</label></div><div class="blocks"><div class="language-bash active"><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;">bin/setup-runtime</span></span></code></pre></div><div class="language-powershell"><button title="Copy Code" class="copy"></button><span class="lang">powershell</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;">.\\bin\\setup</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">runtime.ps1</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.\\bin\\setup</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">runtime.ps1 </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">add-path</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # 将 runtime/ 加入 PATH</span></span></code></pre></div></div></div><p>脚本执行完成后,会在项目目录下生成 <code>runtime/</code> 子目录,其中包含 <code>php</code> 和 <code>composer</code> 两个可执行文件。安装完成后有两种使用方式:</p><ol><li><p><strong>直接通过路径调用</strong>(无需修改环境变量):</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;">runtime/php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bin/spc</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --help</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">runtime/php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> runtime/composer</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span></span></code></pre></div></li><li><p><strong>将 <code>runtime/</code> 加入 PATH</strong>(之后可直接使用 <code>php</code>、<code>composer</code>、<code>bin/spc</code></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:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PATH</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;/path/to/static-php/runtime:</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$PATH</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 建议写入 ~/.bashrc 或 ~/.zshrc 使其永久生效</span></span></code></pre></div></li></ol><h2 id="vendor-模式" tabindex="-1">Vendor 模式 <a class="header-anchor" href="#vendor-模式" aria-label="Permalink to “Vendor 模式”"></a></h2><p>适合在已有 PHP 项目中直接集成 StaticPHP 能力,或通过自定义 registry 支持私有库和扩展的构建。</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;">composer</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> require</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> crazywhalecc/static-php-cli</span></span></code></pre></div><p>Vendor 模式的详细用法见 <a href="./../develop/extending/">扩展 StaticPHP</a>。</p><h2 id="验证构建环境" tabindex="-1">验证构建环境 <a class="header-anchor" href="#验证构建环境" aria-label="Permalink to “验证构建环境”"></a></h2><blockquote><p><strong>Vendor 模式用户可跳过此步骤。</strong></p></blockquote><p>安装完成后,运行 <code>doctor</code> 检查系统构建工具链是否就绪cmake、make、编译器等</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:#6A737D;--shiki-dark:#6A737D;"># 使用 spc 二进制</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> doctor</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 使用源码安装</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> doctor</span></span></code></pre></div><p>如有缺失,<code>--auto-fix</code> 会尝试自动安装修复:</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;"> doctor</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --auto-fix</span></span></code></pre></div><p>检查通过后,继续阅读<a href="./first-build.html">第一次构建</a>。</p>`,30)])])}const g=s(l,[["render",h]]);export{o as __pageData,g as default};