en_guide_env-vars.md.DXDG6yvH.js 8.9 KB

123456
  1. import{_ as e,c as t,o as i,a1 as a}from"./chunks/framework.gjrnbxUT.js";const b=JSON.parse('{"title":"Environment variables","description":"","frontmatter":{},"headers":[],"relativePath":"en/guide/env-vars.md","filePath":"en/guide/env-vars.md"}'),n={name:"en/guide/env-vars.md"},s=a(`<h1 id="environment-variables" tabindex="-1">Environment variables <a class="header-anchor" href="#environment-variables" aria-label="Permalink to &quot;Environment variables&quot;">​</a></h1><p>All environment variables mentioned in the list on this page have default values unless otherwise noted. You can override the default values by setting these environment variables.</p><h2 id="environment-variables-list" tabindex="-1">Environment variables list <a class="header-anchor" href="#environment-variables-list" aria-label="Permalink to &quot;Environment variables list&quot;">​</a></h2><p>Starting from version 2.3.5, we have centralized the environment variables in the <code>config/env.ini</code> file. You can set environment variables by modifying this file.</p><p>We divide the environment variables supported by static-php-cli into three types:</p><ul><li>Global internal environment variables: declared after static-php-cli starts, you can use <code>getenv()</code> to get them internally in static-php-cli, and you can override them before starting static-php-cli.</li><li>Fixed environment variables: declared after static-php-cli starts, you can only use <code>getenv()</code> to get them, but you cannot override them through shell scripts.</li><li>Config file environment variables: declared before static-php-cli build, you can set these environment variables by modifying the <code>config/env.ini</code> file or through shell scripts.</li></ul><p>You can read the comments for each parameter in <a href="https://github.com/crazywhalecc/static-php-cli/blob/main/config/env.ini" target="_blank" rel="noreferrer">config/env.ini</a> to understand its purpose.</p><h2 id="custom-environment-variables" tabindex="-1">Custom environment variables <a class="header-anchor" href="#custom-environment-variables" aria-label="Permalink to &quot;Custom environment variables&quot;">​</a></h2><p>Generally, you don&#39;t need to modify any of the following environment variables as they are already set to optimal values. However, if you have special needs, you can set these environment variables to meet your needs (for example, you need to debug PHP performance under different compilation parameters).</p><p>If you want to use custom environment variables, you can use the <code>export</code> command in the terminal or set the environment variables directly before the command, for example:</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;"># export first</span></span>
  2. <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>
  3. <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>
  4. <span class="line"></span>
  5. <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># or direct use</span></span>
  6. <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><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 &quot;Library environment variables (Unix only)&quot;">​</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 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:#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">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">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, so we currently only support custom environment variables for some libraries.</p><p>If the library you need to customize environment variables is not listed above, you can submit your request through <a href="https://github.com/crazywhalecc/static-php-cli/issues" target="_blank" rel="noreferrer">GitHub Issue</a>.</p></div>`,27),o=[s];function r(l,d,c,p,h,m){return i(),t("div",null,o)}const u=e(n,[["render",r]]);export{b as __pageData,u as default};