Files
static-php-cli/assets/en_faq_index.md.ButqLRAC.js

4 lines
11 KiB
JavaScript
Raw Normal View History

import{_ as i,c as o,o as t,aj as s}from"./chunks/framework.C2AwuPrQ.js";const u=JSON.parse('{"title":"FAQ","description":"","frontmatter":{},"headers":[],"relativePath":"en/faq/index.md","filePath":"en/faq/index.md"}'),a={name:"en/faq/index.md"};function n(l,e,r,c,d,p){return t(),o("div",null,[...e[0]||(e[0]=[s(`<h1 id="faq" tabindex="-1">FAQ <a class="header-anchor" href="#faq" aria-label="Permalink to “FAQ”"></a></h1><p>Here will be some questions that you may encounter easily.</p><h2 id="what-is-the-path-of-php-ini" tabindex="-1">What is the path of php.ini? <a class="header-anchor" href="#what-is-the-path-of-php-ini" aria-label="Permalink to “What is the path of php.ini?”"></a></h2><p>On Linux, macOS and FreeBSD, the path of <code>php.ini</code> is <code>/usr/local/etc/php/php.ini</code>. On Windows, the path is <code>C:\\windows\\php.ini</code> or the current directory of <code>php.exe</code>. The directory where to look for <code>php.ini</code> can be changed on *nix using the build option <code>--with-config-file-path</code>.</p><p>In addition, on Linux, macOS and FreeBSD, <code>.ini</code> files present in the <code>/usr/local/etc/php/conf.d</code> directory will also be loaded. On Windows, this path is empty by default. The directory can be changed using the build option <code>--with-config-file-scan-dir</code>.</p><p><code>php.ini</code> will also be searched for in <a href="https://www.php.net/manual/configuration.file.php" target="_blank" rel="noreferrer">the other standard locations</a>.</p><h2 id="can-statically-compiled-php-install-extensions" tabindex="-1">Can statically-compiled PHP install extensions? <a class="header-anchor" href="#can-statically-compiled-php-install-extensions" aria-label="Permalink to “Can statically-compiled PHP install extensions?”"></a></h2><p>Because the principle of installing PHP extensions under the normal mode is to use <code>.so</code> type dynamic link library to install new extensions, and we use the static link PHP compiled by this project. However, static linking has different definitions in different operating systems.</p><p>First of all, for Linux systems, statically linked binaries will not link the system&#39;s dynamic link library. Purely statically linked binaries (<code>build with -all-static</code>) cannot load dynamic libraries, so new extensions cannot be added. At the same time, in pure static mode, you cannot use extensions such as <code>ffi</code> to load external <code>.so</code> modules.</p><p>You can use the command <code>ldd buildroot/bin/php</code> to check whether the binary you built under Linux is purely statically linked.</p><p>If you build GNU libc based PHP, you can use the <code>ffi</code> extension to load external <code>.so</code> modules and load <code>.so</code> extensions with the same ABI.</p><p>For example, you can use the following command to build a static PHP binary dynamically linked with glibc, supporting FFI extensions and loading the <code>xdebug.so</code> extension of the same PHP version and the same TS type:</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:#24292E;--shiki-dark:#E1E4E8;">SPC_TARGET</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">native-native-gnu.2.17</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> spc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build:php</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;ffi,xml&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --build-cli</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -vvv</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>This uses the Zig toolchain to produce a partially static binary dynamically linked against glibc 2.17. No Docker and no extra cross-compilation toolchain are required.</p><p>For macOS platform, almost all binaries under macOS cannot be truly purely statically linked, and almost all binaries will link macOS system libraries: <code>/usr/lib/libresolv.9.dylib</code> and <code>/usr/lib/libSystem.B.dylib</code>. So on macOS, you can <strong>directly</strong> use SPC to build statically compiled PHP binaries with dynamically linked extensions:</p><ol><li>Build shared extension <code>xxx.so</code> using: <code>--build-shared=XXX</code> option. e.g. <code>spc build:php &quot;bcmath,zlib&quot; --build-shared=xdebug --build-cli</code></li><li>You will get <code>buildroot/modules/xdebug.so</code> and <code>buildroot/bin/php</code>.</li><li>The <code>xdebug.so</code> file could be used for php that version and thread-safe are the same.</li></ol><p>For the Windows platform, since officially built extensions (such as <code>php_yaml.dll</code>) force the use of the <code>php8.dll</code> dynamic library as a link, and statically built PHP does not include any dynamic libraries other than system libraries, php.exe built by static-php cannot load officially built dynamic extensions. Since StaticPHP does not yet support building dynamic extensions, there is currently no way to load dynamic extensions with static-php.</p><p>However, Windows can normally use the <code>FFI</code> extension to load other dll files and call them.</p><h2 id="can-it-support-oracle-database-extension" tabindex="-1">Can it support Oracle database extension? <a class="header-anchor" href="#can-it-support-oracle-database-extension" aria-label="Permalink to Can it support Oracle database extension?"></a></h2><p>Some extensions that rely on closed source libraries, such as <code>oci8</code>, <code>sourceguardian</code>, etc., they do not provide purely statically compiled dependent library files (<code>.a</code>), only dynamic dependent library files (<code>.so</code>). These extensions cannot be compiled into StaticPHP using source code, so this project may never support these extensions. However, in theory you can access and use such extensions under macOS and Linux according to the above questions.</p><h2 id="does-it-support-windows" tabindex="-1">Does it support Windows? <a class="header-anchor" href="#does-it-support-windows" aria-label="Permalink to Does it support Windows?"></a></h2><p>The project currently supports Windows, but the number of supported extensions is small. Windows support is not perfect. There are mainly the following problems:</p><ol><li>The compilation process of Windows is different from that of *nix, and the toolchain used is also different. The compilation tools used to compile the dependent libraries of each extension are almost completely different.</li><li>The demand for the Windows version will also be advanced based on the needs of all people who use this project. If many people need it, I will support related extensions as soon as possible.</li></ol><h2 id="can-i-protect-my-source-code-with-micro" tabindex="-1">Can I protect my source code with micro? <a class="header-anchor" href="#can-i-protect-my-source-code-with-micro" aria-label="Permalink to Can I protect my source code with micro?"></a></h2><p>You can&#39;t. micro.sfx is essentially combining php and php code into one file, there is no process of compiling or encrypting the PHP code.</p><p>First of all, php-src is the official interpreter of PHP code, and there is no PHP compiler compa