static-php-cli/en/guide/env-vars.html

36 lines
32 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>Environment variables | 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 v2.0.0-alpha.12">
<link rel="preload stylesheet" href="/assets/style.DCggPa4H.css" as="style">
<link rel="preload stylesheet" href="/vp-icons.css" as="style">
<script type="module" src="/assets/app.C9FYtCRt.js"></script>
<link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/assets/chunks/theme.MOrVMOSc.js">
<link rel="modulepreload" href="/assets/chunks/framework.Bhsyh9kO.js">
<link rel="modulepreload" href="/assets/en_guide_env-vars.md.51DQ7bvx.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-1df9f90f><!--[--><!--]--><!--[--><span tabindex="-1" data-v-0b0ada53></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-0b0ada53>Skip to content</a><!--]--><!----><header class="VPNav" data-v-1df9f90f data-v-9f75dce3><div class="VPNavBar" data-v-9f75dce3 data-v-2a96a3d0><div class="wrapper" data-v-2a96a3d0><div class="container" data-v-2a96a3d0><div class="title" data-v-2a96a3d0><div class="VPNavBarTitle has-sidebar" data-v-2a96a3d0 data-v-1e38c6bc><a class="title" href="/en/" data-v-1e38c6bc><!--[--><!--]--><!----><span data-v-1e38c6bc>static-php-cli</span><!--[--><!--]--></a></div></div><div class="content" data-v-2a96a3d0><div class="content-body" data-v-2a96a3d0><!--[--><!--]--><div class="VPNavBarSearch search" data-v-2a96a3d0><!--[--><!----><div id="docsearch"><button type="button" aria-label="Search" aria-keyshortcuts="/ control+k meta+k" class="DocSearch DocSearch-Button"><span class="DocSearch-Button-Container"><span class="vpi-search DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key"></kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-2a96a3d0 data-v-39714824><span id="main-nav-aria-label" class="visually-hidden" data-v-39714824> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/guide/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Guide</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/develop/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Advanced</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/contributing/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>Contributing</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/en/faq/" tabindex="0" data-v-39714824 data-v-e56f3d57><!--[--><span data-v-e56f3d57>FAQ</span><!--]--></a><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-2a96a3d0 data-v-88af2de4 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-88af2de4><p class="title" data-v-88af2de4>English</p><!--[--><div class="VPMenuLink" data-v-88af2de4 data-v-cd834e02><a class="VPLink link" href="/zh/guide/env-vars.html" data-v-cd834e02><!--[--><span data-v-cd834e02>简体中文</span><!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-2a96a3d0 data-v-6c893767><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-6c893767 data-v-5337faa4 data-v-1d5665e3><span class="check" data-v-1d5665e3><span class="icon" data-v-1d5665e3><!--[--><span class="vpi-sun sun" data-v-5337faa4></span><span class="vpi-moon moon" data-v-5337faa4></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-2a96a3d0 data-v-0394ad82 data-v-d07f11e6><!--[--><a class="VPSocialLink no-icon" href="https://github.com/crazywhalecc/static-php-cli" aria-label="github" target="_blank" rel="me noopener" data-v-d07f11e6 data-v-591a6b30><span class="vpi-social-github"></span></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-2a96a3d0 data-v-bb2aa2f0 data-v-42cb505d><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-42cb505d><span class="vpi-more-horizontal icon" data-v-42cb505
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> SPC_CONCURRENCY</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">4</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;"> mbstring,pcntl</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;"># or direct use</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SPC_CONCURRENCY</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">4</span><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;"> mbstring,pcntl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span></span></code></pre></div><p>Or, if you need to modify an environment variable for a long time, you can modify the <code>config/env.ini</code> file.</p><p><code>config/env.ini</code> is divided into three sections, <code>[global]</code> is globally effective, <code>[windows]</code>, <code>[macos]</code>, <code>[linux]</code> are only effective for the corresponding operating system.</p><p>For example, if you need to modify the <code>./configure</code> command for compiling PHP, you can find the <code>SPC_CMD_PREFIX_PHP_CONFIGURE</code> environment variable in the <code>config/env.ini</code> file, and then modify its value.</p><p>If your build conditions are more complex and require multiple <code>env.ini</code> files to switch, we recommend that you use the <code>config/env.custom.ini</code> file. In this way, you can specify your environment variables by writing additional override items without modifying the default <code>config/env.ini</code> file.</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:#6A737D;--shiki-dark:#6A737D;">; This is an example of `config/env.custom.ini` file, </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">; we modify the `SPC_CONCURRENCY` and linux default CFLAGS passing to libs and PHP</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">[global]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">SPC_CONCURRENCY</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=4</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">[linux]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">SPC_DEFAULT_C_FLAGS</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;-O3&quot;</span></span></code></pre></div><h2 id="library-environment-variables-unix-only" tabindex="-1">Library environment variables (Unix only) <a class="header-anchor" href="#library-environment-variables-unix-only" aria-label="Permalink to “Library environment variables (Unix only)”"></a></h2><p>Starting from 2.2.0, static-php-cli supports custom environment variables for all compilation dependent library commands of macOS, Linux, FreeBSD and other Unix systems.</p><p>In this way, you can adjust the behavior of compiling dependent libraries through environment variables at any time. For example, you can set the optimization parameters for compiling the xxx library through <code>xxx_CFLAGS=-O0</code>.</p><p>Of course, not every library supports the injection of environment variables. We currently provide three wildcard environment variables with the suffixes:</p><ul><li><code>_CFLAGS</code>: CFLAGS for the compiler</li><li><code>_LDFLAGS</code>: LDFLAGS for the linker</li><li><code>_LIBS</code>: LIBS for the linker</li></ul><p>The prefix is the name of the dependent library, and the specific name of the library is subject to <code>lib.json</code>. Among them, the library name with <code>-</code> needs to replace <code>-</code> with <code>_</code>.</p><p>Here is an example of an optimization option that replaces the openssl library compilation:</p><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:#24292E;--shiki-dark:#E1E4E8;">openssl_CFLAGS</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;-O0&quot;</span></span></code></pre></div><p>The library name uses the same name listed in <code>lib.json</code> and is case-sensitive.</p><div class="tip custom-block"><p class="custom-block-title custom-block-title-default">TIP</p><p>When no relevant environment variables are specified, except for the following variables, the remaining values are empty by default:</p><table tabindex="0"><thead><tr><th>var name</th><th>var default value</th></tr></thead><tbody><tr><td><code>pkg_config_CFLAGS</code></td><td>macOS: <code>$SPC_DEFAULT_C_FLAGS -Wimplicit-function-declaration -Wno-int-conversion</code>, Other: empty</td></tr><tr><td><code>pkg_config_LDFLAGS</code></td><td>Linux: <code>--static</code>, Other: empty</td></tr><tr><td><code>imagemagick_LDFLAGS</code></td><td>Linux: <code>-static</code>, Other: empty</td></tr><tr><td><code>imagemagick_LIBS</code></td><td>macOS: <code>-liconv</code>, Other: empty</td></tr><tr><td><code>ldap_LDFLAGS</code></td><td><code>-L$BUILD_LIB_PATH</code></td></tr><tr><td><code>openssl_CFLAGS</code></td><td>Linux: <code>$SPC_DEFAULT_C_FLAGS</code>, Other: empty</td></tr><tr><td>others...</td><td>empty</td></tr></tbody></table></div><p>The following table is a list of library names that support customizing the above three variables:</p><table tabindex="0"><thead><tr><th>lib name</th></tr></thead><tbody><tr><td>brotli</td></tr><tr><td>bzip</td></tr><tr><td>curl</td></tr><tr><td>freetype</td></tr><tr><td>gettext</td></tr><tr><td>gmp</td></tr><tr><td>imagemagick</td></tr><tr><td>ldap</td></tr><tr><td>libargon2</td></tr><tr><td>libavif</td></tr><tr><td>libcares</td></tr><tr><td>libevent</td></tr><tr><td>openssl</td></tr></tbody></table><div class="tip custom-block"><p class="custom-block-title custom-block-title-default">TIP</p><p>Because adapting custom environment variables to each library is a particularly tedious task, and in most cases you do not need custom environment variables for these libraries,
<script>window.__VP_HASH_MAP__=JSON.parse("{\"deps-craft-yml.md\":\"DqNYV3B0\",\"deps-map-ext.md\":\"BVAR3McO\",\"deps-map-lib.md\":\"BnsDnV_s\",\"en_contributing_index.md\":\"fCA6lXnW\",\"en_develop_craft-yml.md\":\"Ci97ssL7\",\"en_develop_doctor-module.md\":\"BTDyp-aK\",\"en_develop_index.md\":\"DUNrUVP9\",\"en_develop_php-src-changes.md\":\"dN8aSiwg\",\"en_develop_source-module.md\":\"hhJuiZD0\",\"en_develop_structure.md\":\"X2JId3N9\",\"en_develop_system-build-tools.md\":\"BmQhyTle\",\"en_faq_index.md\":\"B89Sredc\",\"en_guide_action-build.md\":\"Dnzq6gNC\",\"en_guide_build-on-windows.md\":\"DiYVSaPG\",\"en_guide_build-with-glibc.md\":\"CkVR75n5\",\"en_guide_cli-generator.md\":\"q_BZ_Z7C\",\"en_guide_deps-map.md\":\"BUF4uebw\",\"en_guide_env-vars.md\":\"51DQ7bvx\",\"en_guide_extension-notes.md\":\"CHFGRiKx\",\"en_guide_extensions.md\":\"UqRV3ESR\",\"en_guide_index.md\":\"BC5dTAQW\",\"en_guide_manual-build.md\":\"DPsGII1D\",\"en_guide_troubleshooting.md\":\"D19jRB1K\",\"en_index.md\":\"WiGlW8EH\",\"extension-notes.md\":\"BB7Xlw1w\",\"extensions.md\":\"hO1GVZPt\",\"index.md\":\"AJG02Jxt\",\"zh_contributing_index.md\":\"fiiKMXnj\",\"zh_develop_craft-yml.md\":\"CAUu6v38\",\"zh_develop_doctor-module.md\":\"1NRXIINs\",\"zh_develop_index.md\":\"CRxnJZDt\",\"zh_develop_php-src-changes.md\":\"CwVUc0oE\",\"zh_develop_source-module.md\":\"3iGbQTPs\",\"zh_develop_structure.md\":\"CEd1RycZ\",\"zh_develop_system-build-tools.md\":\"CQ4BvPVa\",\"zh_faq_index.md\":\"BihV7puH\",\"zh_guide_action-build.md\":\"CQ3Vf3i9\",\"zh_guide_build-on-windows.md\":\"oogWrPn_\",\"zh_guide_build-with-glibc.md\":\"CHXyK61r\",\"zh_guide_cli-generator.md\":\"iYR_rOpk\",\"zh_guide_deps-map.md\":\"Cu7XhPTT\",\"zh_guide_env-vars.md\":\"CtNlqGk4\",\"zh_guide_extension-notes.md\":\"BCwDjBZH\",\"zh_guide_extensions.md\":\"DEhoyCES\",\"zh_guide_index.md\":\"C3GV6eqU\",\"zh_guide_manual-build.md\":\"C3iksvHw\",\"zh_guide_troubleshooting.md\":\"BRQLW2WP\",\"zh_index.md\":\"Dv99zA_s\"}");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\"}],\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2023-present crazywhalecc\"},\"search\":{\"provider\":\"algolia\",\"options\":{\"appId\":\"IHJHUB1SF1\",\"apiKey\":\"8266d31cc2ffbd0e059f1c6e5bdaf8fc\",\"indexName\":\"static-php docs\"}}},\"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
</body>
</html>