static-php-cli/zh/faq/index.html

28 lines
26 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>常见问题 | 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.B_PHkrN1.css" as="style">
<script type="module" src="/assets/app.D3H8Y1BO.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.gjrnbxUT.js">
<link rel="modulepreload" href="/assets/chunks/theme.5IQMzWyn.js">
<link rel="modulepreload" href="/assets/zh_faq_index.md.CGJwisr-.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 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" data-v-ccf7ddec data-v-ab179fa1><a class="title" href="/zh/" 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="/zh/guide/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>构建指南</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/zh/develop/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>进阶</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/zh/contributing/" tabindex="0" data-v-7f418b0f data-v-9c663999><!--[--><span data-v-9c663999>贡献</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/zh/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>简体中文</p><!--[--><div class="VPMenuLink" data-v-88af2de4 data-v-43f1e123><a class="VPLink link" href="/en/faq/" data-v-43f1e123><!--[-->English<!--]--></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>简体中文</p><!--[--><div class="VPMenuLink" data-v-d0bd9dde data-v-43f1e123><a class="VPLink link" href="/en/faq/" data-v-43f1e123><!--[-->English<!--]--></a></div><!--]--></div><div class="group" data-v-d0bd9dde><div class="item appearance" data-v-d0bd9dde><p
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">bin/spc-gnu-docker</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ffi,xml</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --debug</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">buildroot/bin/php</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;zend_extension=/path/to/php{PHP_VER}-{ts/nts}/xdebug.so&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --ri</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> xdebug</span></span></code></pre></div><p>对于 macOS 平台来说macOS 下的几乎所有二进制文件都无法真正纯静态链接,几乎所有二进制文件都会链接 macOS 的系统库:<code>/usr/lib/libresolv.9.dylib</code><code>/usr/lib/libSystem.B.dylib</code>。 所以在 macOS 系统下,在特定的编译条件下可以使用静态编译的 php 二进制文件,可使用动态链接的扩展:</p><ol><li>使用 <code>--no-strip</code> 参数,将不会对二进制文件去除调试符号等信息,以供使用 <code>Xdebug</code> 等外部 Zend 扩展。</li><li>如果要编译某些 Zend 扩展,使用 Homebrew、MacPorts、源码编译的形式在所在的操作系统安装一个普通版本的 PHP。</li><li>使用 <code>phpize &amp;&amp; ./configure &amp;&amp; make</code> 命令编译想要使用的扩展。</li><li>将扩展文件 <code>xxxx.so</code> 拷贝到外部,使用静态编译的 PHP 二进制,例如使用 Xdebug 扩展:<code>cd buildroot/bin/ &amp;&amp; ./php -d &quot;zend_extension=/path/to/xdebug.so&quot;</code></li></ol><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</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;"># 构建静态 php-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;"> ffi</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --no-strip</span></span></code></pre></div><h2 id="可以支持-oracle-数据库扩展吗" tabindex="-1">可以支持 Oracle 数据库扩展吗 <a class="header-anchor" href="#可以支持-oracle-数据库扩展吗" aria-label="Permalink to &quot;可以支持 Oracle 数据库扩展吗&quot;"></a></h2><p>部分依赖库闭源的扩展,如 <code>oci8</code><code>sourceguardian</code> 等,它们没有提供纯静态编译的依赖库文件(<code>.a</code>),仅提供了动态依赖库文件(<code>.so</code> 这些扩展无法使用源码的形式编译到 static-php-cli 中,所以本项目可能永远也不会支持这些扩展。不过,理论上你可以根据上面的问题在 macOS 和 Linux 下接入和使用这类扩展。</p><p>如果你对此类扩展有需求,或者大部分人都对这些闭源扩展使用有需求, 可以看看有关 <a href="https://github.com/crazywhalecc/static-php-cli/discussions/58" target="_blank" rel="noreferrer">standalone-php-cli</a> 的讨论。欢迎留言。</p><h2 id="支持-windows-吗" tabindex="-1">支持 Windows 吗 <a class="header-anchor" href="#支持-windows-吗" aria-label="Permalink to &quot;支持 Windows 吗&quot;"></a></h2><p>该项目目前已支持 Windows但支持的扩展数量较少Windows 的支持并不完美,主要有以下几个问题:</p><ol><li>Windows 的编译流程与 *nix 不同,使用的工具链也不同,编译各个扩展的依赖库使用的编译工具也几乎完全不同。</li><li>Windows 版本的需求也会根据所有使用本项目的人的需求推进,如果有很多人需要,我会尽快支持相关扩展。</li></ol><h2 id="使用-micro-可以保护我的源码吗" tabindex="-1">使用 micro 可以保护我的源码吗 <a class="header-anchor" href="#使用-micro-可以保护我的源码吗" aria-label="Permalink to &quot;使用 micro 可以保护我的源码吗&quot;"></a></h2><p>不可以。micro.sfx 本质上是将 php 和 php 代码结合为一个文件,没有 PHP 代码编译或加密的过程。 首先 php-src 是 PHP 代码的官方解释器,而且现在市面上还没有一个能兼容主流分支的 PHP 编译器。 之前我在网上看到有一个项目是 BPCBinary PHP Compiler可以把 PHP 编译为二进制,但是限制也是很多很多。</p><p>加密保护代码的方向和编译也不是一回事,编译过后也可以通过逆向工程等方式拿到代码,真正保护还是通过加壳、加密代码等手段进行。</p><p>所以本项目static-php-cli、相关项目lwmbs、swoole-cli都是提供一个对 php-src 源码的便捷编译工具, 本项目和相关项目引用的 phpmicro 也仅仅是 PHP 的 sapi 接口封装,而不是 PHP 代码的编译工具。 PHP 代码的编译器是完全不同的项目,因此不会考虑额外的情况。如果你对加密感兴趣,可以考虑使用现有的加密技术,如 Swoole Compiler、Source Guardian 等。</p><h2 id="无法使用-ssl" tabindex="-1">无法使用 ssl <a class="header-anchor" href="#无法使用-ssl" aria-label="Permalink to &quot;无法使用 ssl&quot;"></a></h2><p><strong>更新:该问题已在最新版本的 static-php-cli 中修复,现在默认读取系统的证书文件。如果你仍然遇到问题,再尝试下方的解决方案。</strong></p><p>使用 curl、pgsql 等 请求 HTTPS 网站或建立 SSL 连接时,可能存在 <code>error:80000002:system library::No such file or directory</code> 错误, 这个错误是由于静态编译的 PHP 未通过 <code>php.ini</code> 指定 <code>openssl.cafile</code> 导致的。</p><p>你可以在使用 PHP 前指定 <code>php.ini</code>,并在 I
<script>window.__VP_HASH_MAP__=JSON.parse("{\"en_contributing_index.md\":\"CsY8mx8F\",\"en_develop_php-src-changes.md\":\"DLlooohw\",\"en_develop_system-build-tools.md\":\"D6vaAwN3\",\"en_develop_source-module.md\":\"CdOHR0ez\",\"deps-craft-yml.md\":\"DdOLH9fb\",\"en_develop_doctor-module.md\":\"DGd8PeM_\",\"en_guide_build-on-windows.md\":\"0XosmiyO\",\"en_guide_env-vars.md\":\"CMHjddfB\",\"zh_guide_action-build.md\":\"DWMlBDvT\",\"zh_develop_structure.md\":\"B-0RMSSw\",\"en_guide_build-with-glibc.md\":\"CR2nDLf8\",\"en_guide_action-build.md\":\"BKamBazh\",\"en_guide_cli-generator.md\":\"BVb63i-q\",\"en_develop_index.md\":\"B7_c9YYa\",\"deps-map-lib.md\":\"D13FvK2Q\",\"en_develop_structure.md\":\"BA5PDIse\",\"en_faq_index.md\":\"Dk3Q4ZlV\",\"deps-map-ext.md\":\"CKpfVu5J\",\"en_index.md\":\"Cbpb4iAg\",\"en_guide_extension-notes.md\":\"D_szqpv1\",\"zh_index.md\":\"LslJ1UMp\",\"en_guide_extensions.md\":\"CvNq1b9J\",\"zh_develop_doctor-module.md\":\"DgFAPT6E\",\"zh_guide_extension-notes.md\":\"BwAQ8Pky\",\"zh_develop_system-build-tools.md\":\"Ds53VEw1\",\"zh_guide_cli-generator.md\":\"BQovOB62\",\"zh_guide_build-on-windows.md\":\"BxVEYT8r\",\"zh_guide_deps-map.md\":\"DuTyzThf\",\"zh_guide_env-vars.md\":\"C-N0X5FV\",\"zh_develop_php-src-changes.md\":\"Df0-NcBw\",\"en_develop_craft-yml.md\":\"B3k-Nl-b\",\"en_guide_manual-build.md\":\"BU7HLqGh\",\"zh_develop_source-module.md\":\"D0odLsHX\",\"en_guide_index.md\":\"BScdGPaV\",\"extensions.md\":\"B7vVUihc\",\"en_guide_troubleshooting.md\":\"CTxnPJxK\",\"index.md\":\"mKXtywCA\",\"zh_contributing_index.md\":\"BvgdahxO\",\"zh_guide_extensions.md\":\"HviYRhA7\",\"zh_develop_craft-yml.md\":\"Crgeurk7\",\"zh_develop_index.md\":\"-CPpDfMx\",\"en_guide_deps-map.md\":\"C7t3AggN\",\"zh_faq_index.md\":\"CGJwisr-\",\"zh_guide_build-with-glibc.md\":\"6Wr3xgOs\",\"zh_guide_manual-build.md\":\"Rx1xsyX8\",\"extension-notes.md\":\"Bw8xYOie\",\"zh_guide_index.md\":\"20ged7P4\",\"zh_guide_troubleshooting.md\":\"DAr4n5J3\"}");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\":\"Basic Build Guides\",\"items\":[{\"text\":\"Guide\",\"link\":\"/en/guide/\"},{\"text\":\"Build (Local)\",\"link\":\"/en/guide/manual-build\"},{\"text\":\"Build (CI)\",\"link\":\"/en/guide/action-build\"},{\"text\":\"Supported Extensions\",\"link\":\"/en/guide/extensions\"},{\"text\":\"Extension Notes\",\"link\":\"/en/guide/extension-notes\"},{\"text\":\"Build Command Generator\",\"link\":\"/en/guide/cli-generator\"},{\"text\":\"Environment Variables\",\"link\":\"/en/guide/env-vars\",\"collapsed\":true},{\"text\":\"Dependency Table\",\"link\":\"/en/guide/deps-map\"}]},{\"text\":\"Extended Build Guides\",\"items\":[{\"text\":\"Troubleshooting\",\"link\":\"/en/guide/troubleshooting\"},{\"text\":\"Build on Windows\",\"link\":\"/en/guide/build-on-windows\"},{\"text\":\"Build with GNU libc\",\"link\":\"/en/guide/build-with-glibc\"}]}],\"/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\"
</body>
</html>