mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
feat: better default for the php.ini path (#553)
* update * update * fix * Adjust docs * Adjust docs * Add config-file-scan-dir for WindowsBuilder * Bump version --------- Co-authored-by: crazywhalecc <jesse2061@outlook.com>
This commit is contained in:
parent
ef18264de3
commit
0fb7784a20
@ -2,7 +2,19 @@
|
|||||||
|
|
||||||
Here will be some questions that you may encounter easily. There are currently many, but I need to take time to organize them.
|
Here will be some questions that you may encounter easily. There are currently many, but I need to take time to organize them.
|
||||||
|
|
||||||
## Can statically compiled PHP install extensions?
|
## What is the path of php.ini ?
|
||||||
|
|
||||||
|
On Linux, macOS and FreeBSD, the path of `php.ini` is `/usr/local/etc/php/php.ini`.
|
||||||
|
On Windows, the path is `C:\windows\php.ini` or the current directory of `php.exe`.
|
||||||
|
The directory where to look for `php.ini` can be changed on *nix using the manual build option `--with-config-file-path`.
|
||||||
|
|
||||||
|
In addition, on Linux, macOS and FreeBSD, `.ini` files present in the `/usr/local/etc/php/conf.d` directory will also be loaded.
|
||||||
|
On Windows, this path is empty by default.
|
||||||
|
The directory can be changed using the manual build option `--with-config-file-scan-dir`.
|
||||||
|
|
||||||
|
`php.ini` will also be searched for in [the other standard locations](https://www.php.net/manual/configuration.file.php).
|
||||||
|
|
||||||
|
## Can statically-compiled PHP install extensions?
|
||||||
|
|
||||||
Because the principle of installing extensions in PHP under the traditional architecture is to install new extensions using `.so` type dynamic link libraries,
|
Because the principle of installing extensions in PHP under the traditional architecture is to install new extensions using `.so` type dynamic link libraries,
|
||||||
and statically linked PHP compiled using this project cannot **directly** install new extensions using dynamic link libraries.
|
and statically linked PHP compiled using this project cannot **directly** install new extensions using dynamic link libraries.
|
||||||
|
|||||||
@ -160,7 +160,7 @@ You can try to use the following commands:
|
|||||||
- `--with-clean`: clean up old make files before compiling PHP
|
- `--with-clean`: clean up old make files before compiling PHP
|
||||||
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
|
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
|
||||||
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extension optional functions
|
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extension optional functions
|
||||||
- `--with-config-file-path=XXX`: Set the path in which to look for php.ini
|
- `--with-config-file-scan-dir=XXX`: Set the directory to scan for `.ini` files after reading `php.ini` (Check [here](../faq/index.html#what-is-the-path-of-php-ini) for default paths)
|
||||||
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
|
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
|
||||||
- `--with-micro-fake-cli`: When compiling micro, let micro's `PHP_SAPI` pretend to be `cli` (for compatibility with some programs that check `PHP_SAPI`)
|
- `--with-micro-fake-cli`: When compiling micro, let micro's `PHP_SAPI` pretend to be `cli` (for compatibility with some programs that check `PHP_SAPI`)
|
||||||
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)
|
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)
|
||||||
|
|||||||
@ -304,7 +304,8 @@ You can try to use the following commands:
|
|||||||
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
|
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
|
||||||
- `--no-strip`: Do not run `strip` after compiling the PHP library to trim the binary file to reduce its size (the macOS binary file without trim can use dynamically linked third-party extensions)
|
- `--no-strip`: Do not run `strip` after compiling the PHP library to trim the binary file to reduce its size (the macOS binary file without trim can use dynamically linked third-party extensions)
|
||||||
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extended optional functions (such as libavif of the gd library, etc.)
|
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extended optional functions (such as libavif of the gd library, etc.)
|
||||||
- `--with-config-file-path=XXX`: Set the path in which to look for php.ini
|
- `--with-config-file-path=XXX`: Set the path in which to look for `php.ini` (Check [here](../faq/index.html#what-is-the-path-of-php-ini) for default paths)
|
||||||
|
- `--with-config-file-scan-dir=XXX`: Set the directory to scan for `.ini` files after reading `php.ini` (Check [here](../faq/index.html#what-is-the-path-of-php-ini) for default paths)
|
||||||
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
|
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
|
||||||
- `--with-micro-fake-cli`: When compiling micro, let micro's `PHP_SAPI` pretend to be `cli` (for compatibility with some programs that check `PHP_SAPI`)
|
- `--with-micro-fake-cli`: When compiling micro, let micro's `PHP_SAPI` pretend to be `cli` (for compatibility with some programs that check `PHP_SAPI`)
|
||||||
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)
|
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)
|
||||||
|
|||||||
@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
这里将会编写一些你容易遇到的问题。目前有很多,但是我需要花时间来整理一下。
|
这里将会编写一些你容易遇到的问题。目前有很多,但是我需要花时间来整理一下。
|
||||||
|
|
||||||
|
## php.ini 的路径是什么?
|
||||||
|
|
||||||
|
在 Linux、macOS 和 FreeBSD 上,`php.ini` 的默认路径是 `/usr/local/etc/php/php.ini`。
|
||||||
|
在 Windows 中,路径是 `C:\windows\php.ini` 或 `php.exe` 所在的当前目录。
|
||||||
|
可以在 *nix 系统中使用手动构建选项 `--with-config-file-path` 来更改查找 `php.ini` 的目录。
|
||||||
|
|
||||||
|
此外,在 Linux、macOS 和 FreeBSD 上,`/usr/local/etc/php/conf.d` 目录中的 `*.ini` 文件也会被加载。
|
||||||
|
在 Windows 中,该路径默认为空。
|
||||||
|
可以使用手动构建选项 `--with-config-file-scan-dir` 更改该目录。
|
||||||
|
|
||||||
|
PHP 默认也会从 [其他标准位置](https://www.php.net/manual/zh/configuration.file.php) 中搜索 `php.ini`。
|
||||||
|
|
||||||
## 静态编译的 PHP 可以安装扩展吗
|
## 静态编译的 PHP 可以安装扩展吗
|
||||||
|
|
||||||
因为传统架构下的 PHP 安装扩展的原理是使用 `.so` 类型的动态链接的库方式安装新扩展,而使用本项目编译的静态链接的 PHP 无法**直接**使用动态链接库安装新扩展。
|
因为传统架构下的 PHP 安装扩展的原理是使用 `.so` 类型的动态链接的库方式安装新扩展,而使用本项目编译的静态链接的 PHP 无法**直接**使用动态链接库安装新扩展。
|
||||||
|
|||||||
@ -146,6 +146,7 @@ bin/spc build "openssl" --build-cli --debug
|
|||||||
- `--with-clean`: 编译 PHP 前先清理旧的 make 产生的文件
|
- `--with-clean`: 编译 PHP 前先清理旧的 make 产生的文件
|
||||||
- `--enable-zts`: 让编译的 PHP 为线程安全版本(默认为 NTS 版本)
|
- `--enable-zts`: 让编译的 PHP 为线程安全版本(默认为 NTS 版本)
|
||||||
- `--with-libs=XXX,YYY`: 编译 PHP 前先编译指定的依赖库,激活部分扩展的可选功能
|
- `--with-libs=XXX,YYY`: 编译 PHP 前先编译指定的依赖库,激活部分扩展的可选功能
|
||||||
|
- `--with-config-file-scan-dir=XXX`: 读取 `php.ini` 后扫描 `.ini` 文件的目录(在 [这里](../faq/index.html#php-ini-的路径是什么) 查看默认路径)
|
||||||
- `-I xxx=yyy`: 编译前将 INI 选项硬编译到 PHP 内(支持多个选项,别名是 `--with-hardcoded-ini`)
|
- `-I xxx=yyy`: 编译前将 INI 选项硬编译到 PHP 内(支持多个选项,别名是 `--with-hardcoded-ini`)
|
||||||
- `--with-micro-fake-cli`: 在编译 micro 时,让 micro 的 SAPI 伪装为 `cli`(用于兼容一些检查 `PHP_SAPI` 的程序)
|
- `--with-micro-fake-cli`: 在编译 micro 时,让 micro 的 SAPI 伪装为 `cli`(用于兼容一些检查 `PHP_SAPI` 的程序)
|
||||||
- `--disable-opcache-jit`: 禁用 opcache jit(默认启用)
|
- `--disable-opcache-jit`: 禁用 opcache jit(默认启用)
|
||||||
|
|||||||
@ -265,7 +265,8 @@ bin/spc build mysqlnd,pdo_mysql --build-all --debug
|
|||||||
- `--enable-zts`: 让编译的 PHP 为线程安全版本(默认为 NTS 版本)
|
- `--enable-zts`: 让编译的 PHP 为线程安全版本(默认为 NTS 版本)
|
||||||
- `--no-strip`: 编译 PHP 库后不运行 `strip` 裁剪二进制文件缩小体积(不裁剪的 macOS 二进制文件可使用动态链接的第三方扩展)
|
- `--no-strip`: 编译 PHP 库后不运行 `strip` 裁剪二进制文件缩小体积(不裁剪的 macOS 二进制文件可使用动态链接的第三方扩展)
|
||||||
- `--with-libs=XXX,YYY`: 编译 PHP 前先编译指定的依赖库,激活部分扩展的可选功能(例如 gd 库的 libavif 等)
|
- `--with-libs=XXX,YYY`: 编译 PHP 前先编译指定的依赖库,激活部分扩展的可选功能(例如 gd 库的 libavif 等)
|
||||||
- `--with-config-file-path=XXX`: 指定 PHP 配置文件的路径
|
- `--with-config-file-path=XXX`: 查找 `php.ini` 的路径(在 [这里](../faq/index.html#php-ini-的路径是什么) 查看默认路径)
|
||||||
|
- `--with-config-file-scan-dir=XXX`: 读取 `php.ini` 后扫描 `.ini` 文件的目录(在 [这里](../faq/index.html#php-ini-的路径是什么) 查看默认路径)
|
||||||
- `-I xxx=yyy`: 编译前将 INI 选项硬编译到 PHP 内(支持多个选项,别名是 `--with-hardcoded-ini`)
|
- `-I xxx=yyy`: 编译前将 INI 选项硬编译到 PHP 内(支持多个选项,别名是 `--with-hardcoded-ini`)
|
||||||
- `--with-micro-fake-cli`: 在编译 micro 时,让 micro 的 SAPI 伪装为 `cli`(用于兼容一些检查 `PHP_SAPI` 的程序)
|
- `--with-micro-fake-cli`: 在编译 micro 时,让 micro 的 SAPI 伪装为 `cli`(用于兼容一些检查 `PHP_SAPI` 的程序)
|
||||||
- `--disable-opcache-jit`: 禁用 opcache jit(默认启用)
|
- `--disable-opcache-jit`: 禁用 opcache jit(默认启用)
|
||||||
|
|||||||
@ -30,7 +30,7 @@ use Symfony\Component\Console\Application;
|
|||||||
*/
|
*/
|
||||||
final class ConsoleApplication extends Application
|
final class ConsoleApplication extends Application
|
||||||
{
|
{
|
||||||
public const VERSION = '2.3.5';
|
public const VERSION = '2.3.6';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -89,6 +89,11 @@ class BSDBuilder extends UnixBuilderBase
|
|||||||
$zts_enable = $this->getPHPVersionID() < 80000 ? '--enable-maintainer-zts --disable-zend-signals' : '--enable-zts --disable-zend-signals';
|
$zts_enable = $this->getPHPVersionID() < 80000 ? '--enable-maintainer-zts --disable-zend-signals' : '--enable-zts --disable-zend-signals';
|
||||||
$zts = $this->getOption('enable-zts', false) ? $zts_enable : '';
|
$zts = $this->getOption('enable-zts', false) ? $zts_enable : '';
|
||||||
|
|
||||||
|
$config_file_path = $this->getOption('with-config-file-path', false) ?
|
||||||
|
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
|
||||||
|
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
|
||||||
|
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
|
||||||
|
|
||||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||||
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||||
@ -109,6 +114,8 @@ class BSDBuilder extends UnixBuilderBase
|
|||||||
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||||
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
|
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
|
||||||
|
$config_file_path .
|
||||||
|
$config_file_scan_dir .
|
||||||
$json_74 .
|
$json_74 .
|
||||||
$zts .
|
$zts .
|
||||||
$this->makeExtensionArgs()
|
$this->makeExtensionArgs()
|
||||||
|
|||||||
@ -136,6 +136,8 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
|
|
||||||
$config_file_path = $this->getOption('with-config-file-path', false) ?
|
$config_file_path = $this->getOption('with-config-file-path', false) ?
|
||||||
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
|
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
|
||||||
|
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
|
||||||
|
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
|
||||||
|
|
||||||
$enable_cli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
$enable_cli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||||
$enable_fpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
$enable_fpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||||
@ -167,6 +169,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
($enable_embed ? '--enable-embed=static ' : '--disable-embed ') .
|
($enable_embed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||||
($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') .
|
($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') .
|
||||||
$config_file_path .
|
$config_file_path .
|
||||||
|
$config_file_scan_dir .
|
||||||
$disable_jit .
|
$disable_jit .
|
||||||
$json_74 .
|
$json_74 .
|
||||||
$zts .
|
$zts .
|
||||||
|
|||||||
@ -139,6 +139,8 @@ class MacOSBuilder extends UnixBuilderBase
|
|||||||
|
|
||||||
$config_file_path = $this->getOption('with-config-file-path', false) ?
|
$config_file_path = $this->getOption('with-config-file-path', false) ?
|
||||||
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
|
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
|
||||||
|
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
|
||||||
|
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
|
||||||
|
|
||||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||||
@ -168,6 +170,7 @@ class MacOSBuilder extends UnixBuilderBase
|
|||||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||||
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
|
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
|
||||||
$config_file_path .
|
$config_file_path .
|
||||||
|
$config_file_scan_dir .
|
||||||
$json_74 .
|
$json_74 .
|
||||||
$zts .
|
$zts .
|
||||||
$this->makeExtensionArgs() . ' ' .
|
$this->makeExtensionArgs() . ' ' .
|
||||||
|
|||||||
@ -103,6 +103,9 @@ class WindowsBuilder extends BuilderBase
|
|||||||
|
|
||||||
$micro_w32 = $this->getOption('enable-micro-win32') ? ' --enable-micro-win32=yes' : '';
|
$micro_w32 = $this->getOption('enable-micro-win32') ? ' --enable-micro-win32=yes' : '';
|
||||||
|
|
||||||
|
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
|
||||||
|
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
|
||||||
|
|
||||||
cmd()->cd(SOURCE_PATH . '\php-src')
|
cmd()->cd(SOURCE_PATH . '\php-src')
|
||||||
->exec(
|
->exec(
|
||||||
"{$this->sdk_prefix} configure.bat --task-args \"" .
|
"{$this->sdk_prefix} configure.bat --task-args \"" .
|
||||||
@ -114,6 +117,7 @@ class WindowsBuilder extends BuilderBase
|
|||||||
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
|
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
|
||||||
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
|
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
|
||||||
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
|
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
|
||||||
|
$config_file_scan_dir .
|
||||||
"{$this->makeExtensionArgs()} " .
|
"{$this->makeExtensionArgs()} " .
|
||||||
$zts .
|
$zts .
|
||||||
'"'
|
'"'
|
||||||
|
|||||||
@ -22,6 +22,8 @@ class BuildCliCommand extends BuildCommand
|
|||||||
{
|
{
|
||||||
public function configure(): void
|
public function configure(): void
|
||||||
{
|
{
|
||||||
|
$isWindows = PHP_OS_FAMILY === 'Windows';
|
||||||
|
|
||||||
$this->addArgument('extensions', InputArgument::REQUIRED, 'The extensions will be compiled, comma separated');
|
$this->addArgument('extensions', InputArgument::REQUIRED, 'The extensions will be compiled, comma separated');
|
||||||
$this->addOption('with-libs', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
$this->addOption('with-libs', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
||||||
$this->addOption('build-micro', null, null, 'Build micro SAPI');
|
$this->addOption('build-micro', null, null, 'Build micro SAPI');
|
||||||
@ -32,7 +34,8 @@ class BuildCliCommand extends BuildCommand
|
|||||||
$this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions');
|
$this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions');
|
||||||
$this->addOption('enable-zts', null, null, 'enable ZTS support');
|
$this->addOption('enable-zts', null, null, 'enable ZTS support');
|
||||||
$this->addOption('disable-opcache-jit', null, null, 'disable opcache jit');
|
$this->addOption('disable-opcache-jit', null, null, 'disable opcache jit');
|
||||||
$this->addOption('with-config-file-path', null, InputOption::VALUE_REQUIRED, 'Set the path in which to look for php.ini');
|
$this->addOption('with-config-file-path', null, InputOption::VALUE_REQUIRED, 'Set the path in which to look for php.ini', $isWindows ? null : '/usr/local/etc/php');
|
||||||
|
$this->addOption('with-config-file-scan-dir', null, InputOption::VALUE_REQUIRED, 'Set the directory to scan for .ini files after reading php.ini', $isWindows ? null : '/usr/local/etc/php/conf.d');
|
||||||
$this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI');
|
$this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI');
|
||||||
$this->addOption('with-micro-fake-cli', null, null, 'Let phpmicro\'s PHP_SAPI use "cli" instead of "micro"');
|
$this->addOption('with-micro-fake-cli', null, null, 'Let phpmicro\'s PHP_SAPI use "cli" instead of "micro"');
|
||||||
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
|
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user