mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
6 lines
12 KiB
JavaScript
6 lines
12 KiB
JavaScript
import{_ as i,c as s,o,af as t}from"./chunks/framework.PeLcR_tw.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 o(),s("div",null,e[0]||(e[0]=[t(`<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. There are currently many, but I need to take time to organize them.</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 manual 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 manual 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'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 <a href="./../guide/build-with-glibc.html">build GNU libc based PHP</a>, 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:#6F42C1;--shiki-dark:#B392F0;">bin/spc-gnu-docker</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> download</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --for-extensions=ffi,xml</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --with-php=8.4</span></span>
|
||
<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;"> "zend_extension=/path/to/php{PHP_VER}-{ts/nts}/xdebug.so"</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>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 use statically compiled PHP binaries under certain compilation conditions, and dynamically linked extensions:</p><ol><li>Using the <code>--no-strip</code> parameter will not strip information such as debugging symbols from the binary file for use with external Zend extensions such as <code>Xdebug</code>.</li><li>If you want to compile some Zend extensions, use Homebrew, MacPorts, source code compilation, and install a normal version of PHP on your operating system.</li><li>Use the <code>phpize && ./configure && make</code> command to compile the extensions you want to use.</li><li>Copy the extension file <code>xxxx.so</code> to the outside, use the statically compiled PHP binary, for example to use the Xdebug extension: <code>cd buildroot/bin/ && ./php -d "zend_extension=/path/to/xdebug.so"</code>.</li></ol><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;"># build statically linked php-cli but not stripped</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="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 static-php-cli 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><p>If you have a need for such extensions, or most people have needs for these closed-source extensions, see the discussion on <a href="https://github.com/crazywhalecc/static-php-cli/discussions/58" target="_blank" rel="noreferrer">standalone-php-cli</a>. Welcome to leave a message.</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'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 compatible with mainstream branches on the market. I saw on the Internet that there is a project called BPC (Binary PHP Compiler?) that can compile PHP into binary, but there are many restrictions.</p><p>The direction of encrypting and protecting the code is not the same as compiling. After compiling, the code can also be obtained through reverse engineering and other methods. The real protection is still carried out by means of packing and encrypting the code.</p><p>Therefore, this project (static-php-cli) and related projects (lwmbs, swoole-cli) all provide a convenient compilation tool for php-src source code. The phpmicro referenced by this project and related projects is only a package of PHP's sapi interface, not a compilation tool for PHP code. The compiler for PHP code is a completely different project, so the extra cases are not taken into account. If you are interested in encryption, you can consider using existing encryption technologies, such as Swoole Compiler, Source Guardian, etc.</p><h2 id="unable-to-use-ssl" tabindex="-1">Unable to use ssl <a class="header-anchor" href="#unable-to-use-ssl" aria-label="Permalink to “Unable to use ssl”"></a></h2><p><strong>Update: This issue has been fixed in the latest version of static-php-cli, which now reads the system's certificate file by default. If you still have problems, try the solution below.</strong></p><p>When using curl, pgsql, etc. to request an HTTPS website or establish an SSL connection, there may be an <code>error:80000002:system library::No such file or directory</code> error. This error is caused by statically compiled PHP without specifying <code>openssl.cafile</code> via <code>php.ini</code>.</p><p>You can solve this problem by specifying <code>php.ini</code> before using PHP and adding <code>openssl.cafile=/path/to/your-cert.pem</code> in the INI.</p><p>For Linux systems, you can download the <a href="https://curl.se/docs/caextract.html" target="_blank" rel="noreferrer">cacert.pem</a> file from the curl official website, or you can use the certificate file that comes with the system. For the certificate locations of different distros, please refer to <a href="https://go.dev/src/crypto/x509/root_linux.go" target="_blank" rel="noreferrer">Golang docs</a>.</p><blockquote><p>INI configuration <code>openssl.cafile</code> cannot be set dynamically using the <code>ini_set()</code> function, because <code>openssl.cafile</code> is a <code>PHP_INI_SYSTEM</code> type configuration and can only be set in the <code>php.ini</code> file.</p></blockquote><h2 id="why-don-t-we-support-older-versions-of-php" tabindex="-1">Why don't we support older versions of PHP? <a class="header-anchor" href="#why-don-t-we-support-older-versions-of-php" aria-label="Permalink to “Why don't we support older versions of PHP?”"></a></h2><p>Because older versions of PHP have many problems, such as security issues, performance issues, and functional issues. In addition, many older versions of PHP are not compatible with the latest dependency libraries, which is one of the reasons why older versions of PHP are not supported.</p><p>You can use older versions compiled earlier by static-php-cli, such as PHP 8.0, but earlier versions will not be explicitly supported.</p>`,36)]))}const m=i(a,[["render",n]]);export{u as __pageData,m as default};
|