|
1 | | -# Frequently Asked Questions |
2 | | - |
3 | | -<!-- TODO: Categorized FAQ. |
4 | | - Sections: |
5 | | - - Build Issues (common compile errors, missing tools) |
6 | | - - Extensions (dynamic loading, closed-source deps, oci8) |
7 | | - - Windows (icon embedding, DLL loading, FFI) |
8 | | - - Version Compatibility (PHP versions, glibc vs musl) |
9 | | - - Source Protection (micro, encryption) |
10 | | - Migrate and expand from v2 faq/index.md. --> |
| 1 | +# FAQ |
| 2 | + |
| 3 | +Here will be some questions that you may encounter easily. |
| 4 | + |
| 5 | +## What is the path of php.ini? |
| 6 | + |
| 7 | +On Linux, macOS and FreeBSD, the path of `php.ini` is `/usr/local/etc/php/php.ini`. |
| 8 | +On Windows, the path is `C:\windows\php.ini` or the current directory of `php.exe`. |
| 9 | +The directory where to look for `php.ini` can be changed on *nix using the build option `--with-config-file-path`. |
| 10 | + |
| 11 | +In addition, on Linux, macOS and FreeBSD, `.ini` files present in the `/usr/local/etc/php/conf.d` directory will also be loaded. |
| 12 | +On Windows, this path is empty by default. |
| 13 | +The directory can be changed using the build option `--with-config-file-scan-dir`. |
| 14 | + |
| 15 | +`php.ini` will also be searched for in [the other standard locations](https://www.php.net/manual/configuration.file.php). |
| 16 | + |
| 17 | +## Can statically-compiled PHP install extensions? |
| 18 | + |
| 19 | +Because the principle of installing PHP extensions under the normal mode is to use `.so` type dynamic link library to install new extensions, |
| 20 | +and we use the static link PHP compiled by this project. However, static linking has different definitions in different operating systems. |
| 21 | + |
| 22 | +First of all, for Linux systems, statically linked binaries will not link the system's dynamic link library. |
| 23 | +Purely statically linked binaries (`build with -all-static`) cannot load dynamic libraries, so new extensions cannot be added. |
| 24 | +At the same time, in pure static mode, you cannot use extensions such as `ffi` to load external `.so` modules. |
| 25 | + |
| 26 | +You can use the command `ldd buildroot/bin/php` to check whether the binary you built under Linux is purely statically linked. |
| 27 | + |
| 28 | +If you build GNU libc based PHP, you can use the `ffi` extension to load external `.so` modules and load `.so` extensions with the same ABI. |
| 29 | + |
| 30 | +For example, you can use the following command to build a static PHP binary dynamically linked with glibc, |
| 31 | +supporting FFI extensions and loading the `xdebug.so` extension of the same PHP version and the same TS type: |
| 32 | + |
| 33 | +```bash |
| 34 | +SPC_TARGET=native-native-gnu.2.17 spc build:php "ffi,xml" --build-cli -vvv |
| 35 | + |
| 36 | +buildroot/bin/php -d "zend_extension=/path/to/php{PHP_VER}-{ts/nts}/xdebug.so" --ri xdebug |
| 37 | +``` |
| 38 | + |
| 39 | +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. |
| 40 | + |
| 41 | +For macOS platform, almost all binaries under macOS cannot be truly purely statically linked, and almost all binaries will link macOS system libraries: `/usr/lib/libresolv.9.dylib` and `/usr/lib/libSystem.B.dylib`. |
| 42 | +So on macOS, you can **directly** use SPC to build statically compiled PHP binaries with dynamically linked extensions: |
| 43 | + |
| 44 | +1. Build shared extension `xxx.so` using: `--build-shared=XXX` option. e.g. `spc build:php "bcmath,zlib" --build-shared=xdebug --build-cli` |
| 45 | +2. You will get `buildroot/modules/xdebug.so` and `buildroot/bin/php`. |
| 46 | +3. The `xdebug.so` file could be used for php that version and thread-safe are the same. |
| 47 | + |
| 48 | +For the Windows platform, since officially built extensions (such as `php_yaml.dll`) force the use of the `php8.dll` dynamic library as a link, and statically built PHP does not include any dynamic libraries other than system libraries, |
| 49 | +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. |
| 50 | + |
| 51 | +However, Windows can normally use the `FFI` extension to load other dll files and call them. |
| 52 | + |
| 53 | +## Can it support Oracle database extension? |
| 54 | + |
| 55 | +Some extensions that rely on closed source libraries, such as `oci8`, `sourceguardian`, etc., |
| 56 | +they do not provide purely statically compiled dependent library files (`.a`), only dynamic dependent library files (`.so`). |
| 57 | +These extensions cannot be compiled into StaticPHP using source code, so this project may never support these extensions. |
| 58 | +However, in theory you can access and use such extensions under macOS and Linux according to the above questions. |
| 59 | + |
| 60 | +## Does it support Windows? |
| 61 | + |
| 62 | +The project currently supports Windows, but the number of supported extensions is small. Windows support is not perfect. There are mainly the following problems: |
| 63 | + |
| 64 | +1. 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. |
| 65 | +2. 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. |
| 66 | + |
| 67 | +## Can I protect my source code with micro? |
| 68 | + |
| 69 | +You can't. micro.sfx is essentially combining php and php code into one file, |
| 70 | +there is no process of compiling or encrypting the PHP code. |
| 71 | + |
| 72 | +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. |
| 73 | +I saw on the Internet that there is a project called BPC (Binary PHP Compiler?) that can compile PHP into binary, |
| 74 | +but there are many restrictions. |
| 75 | + |
| 76 | +The direction of encrypting and protecting the code is not the same as compiling. |
| 77 | +After compiling, the code can also be obtained through reverse engineering and other methods. |
| 78 | +The real protection is still carried out by means of packing and encrypting the code. |
| 79 | + |
| 80 | +Therefore, this project (StaticPHP) and related projects (lwmbs, swoole-cli) all provide a convenient compilation tool for php-src source code. |
| 81 | +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. |
| 82 | +The compiler for PHP code is a completely different project, so the extra cases are not taken into account. |
| 83 | +If you are interested in encryption, you can consider using existing encryption technologies, |
| 84 | +such as Swoole Compiler, Source Guardian, etc. |
| 85 | + |
| 86 | +## Unable to use ssl |
| 87 | + |
| 88 | +**Update: This issue has been fixed in the latest version of StaticPHP, which now reads the system's certificate file by default. If you still have problems, try the solution below.** |
| 89 | + |
| 90 | +When using curl, pgsql, etc. to request an HTTPS website or establish an SSL connection, there may be an `error:80000002:system library::No such file or directory` error. |
| 91 | +This error is caused by statically compiled PHP without specifying `openssl.cafile` via `php.ini`. |
| 92 | + |
| 93 | +You can solve this problem by specifying `php.ini` before using PHP and adding `openssl.cafile=/path/to/your-cert.pem` in the INI. |
| 94 | + |
| 95 | +For Linux systems, you can download the [cacert.pem](https://curl.se/docs/caextract.html) file from the curl official website, or you can use the certificate file that comes with the system. |
| 96 | +For the certificate locations of different distros, please refer to [Golang docs](https://go.dev/src/crypto/x509/root_linux.go). |
| 97 | + |
| 98 | +> INI configuration `openssl.cafile` cannot be set dynamically using the `ini_set()` function, because `openssl.cafile` is a `PHP_INI_SYSTEM` type configuration and can only be set in the `php.ini` file. |
| 99 | +
|
| 100 | +## Why don't we support older versions of PHP? |
| 101 | + |
| 102 | +Because older versions of PHP have many problems, such as security issues, performance issues, and functional issues. |
| 103 | +In addition, many older versions of PHP are not compatible with the latest dependency libraries, |
| 104 | +which is one of the reasons why older versions of PHP are not supported. |
| 105 | + |
| 106 | +You can use older versions compiled earlier by StaticPHP, such as PHP 8.0, but earlier versions will not be explicitly supported. |
| 107 | + |
0 commit comments