Skip to content

Commit 0fb7784

Browse files
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 <[email protected]>
1 parent ef18264 commit 0fb7784

File tree

12 files changed

+53
-6
lines changed

12 files changed

+53
-6
lines changed

docs/en/faq/index.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
Here will be some questions that you may encounter easily. There are currently many, but I need to take time to organize them.
44

5-
## Can statically compiled PHP install extensions?
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 manual 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 manual 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?
618

719
Because the principle of installing extensions in PHP under the traditional architecture is to install new extensions using `.so` type dynamic link libraries,
820
and statically linked PHP compiled using this project cannot **directly** install new extensions using dynamic link libraries.

docs/en/guide/build-on-windows.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ You can try to use the following commands:
160160
- `--with-clean`: clean up old make files before compiling PHP
161161
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
162162
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extension optional functions
163-
- `--with-config-file-path=XXX`: Set the path in which to look for php.ini
163+
- `--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)
164164
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
165165
- `--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`)
166166
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)

docs/en/guide/manual-build.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ You can try to use the following commands:
304304
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
305305
- `--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)
306306
- `--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.)
307-
- `--with-config-file-path=XXX`: Set the path in which to look for php.ini
307+
- `--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)
308+
- `--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)
308309
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
309310
- `--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`)
310311
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)

docs/zh/faq/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
这里将会编写一些你容易遇到的问题。目前有很多,但是我需要花时间来整理一下。
44

5+
## php.ini 的路径是什么?
6+
7+
在 Linux、macOS 和 FreeBSD 上,`php.ini` 的默认路径是 `/usr/local/etc/php/php.ini`
8+
在 Windows 中,路径是 `C:\windows\php.ini``php.exe` 所在的当前目录。
9+
可以在 *nix 系统中使用手动构建选项 `--with-config-file-path` 来更改查找 `php.ini` 的目录。
10+
11+
此外,在 Linux、macOS 和 FreeBSD 上,`/usr/local/etc/php/conf.d` 目录中的 `*.ini` 文件也会被加载。
12+
在 Windows 中,该路径默认为空。
13+
可以使用手动构建选项 `--with-config-file-scan-dir` 更改该目录。
14+
15+
PHP 默认也会从 [其他标准位置](https://www.php.net/manual/zh/configuration.file.php) 中搜索 `php.ini`
16+
517
## 静态编译的 PHP 可以安装扩展吗
618

719
因为传统架构下的 PHP 安装扩展的原理是使用 `.so` 类型的动态链接的库方式安装新扩展,而使用本项目编译的静态链接的 PHP 无法**直接**使用动态链接库安装新扩展。

docs/zh/guide/build-on-windows.md

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ bin/spc build "openssl" --build-cli --debug
146146
- `--with-clean`: 编译 PHP 前先清理旧的 make 产生的文件
147147
- `--enable-zts`: 让编译的 PHP 为线程安全版本(默认为 NTS 版本)
148148
- `--with-libs=XXX,YYY`: 编译 PHP 前先编译指定的依赖库,激活部分扩展的可选功能
149+
- `--with-config-file-scan-dir=XXX`: 读取 `php.ini` 后扫描 `.ini` 文件的目录(在 [这里](../faq/index.html#php-ini-的路径是什么) 查看默认路径)
149150
- `-I xxx=yyy`: 编译前将 INI 选项硬编译到 PHP 内(支持多个选项,别名是 `--with-hardcoded-ini`
150151
- `--with-micro-fake-cli`: 在编译 micro 时,让 micro 的 SAPI 伪装为 `cli`(用于兼容一些检查 `PHP_SAPI` 的程序)
151152
- `--disable-opcache-jit`: 禁用 opcache jit(默认启用)

docs/zh/guide/manual-build.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ bin/spc build mysqlnd,pdo_mysql --build-all --debug
265265
- `--enable-zts`: 让编译的 PHP 为线程安全版本(默认为 NTS 版本)
266266
- `--no-strip`: 编译 PHP 库后不运行 `strip` 裁剪二进制文件缩小体积(不裁剪的 macOS 二进制文件可使用动态链接的第三方扩展)
267267
- `--with-libs=XXX,YYY`: 编译 PHP 前先编译指定的依赖库,激活部分扩展的可选功能(例如 gd 库的 libavif 等)
268-
- `--with-config-file-path=XXX`: 指定 PHP 配置文件的路径
268+
- `--with-config-file-path=XXX`: 查找 `php.ini` 的路径(在 [这里](../faq/index.html#php-ini-的路径是什么) 查看默认路径)
269+
- `--with-config-file-scan-dir=XXX`: 读取 `php.ini` 后扫描 `.ini` 文件的目录(在 [这里](../faq/index.html#php-ini-的路径是什么) 查看默认路径)
269270
- `-I xxx=yyy`: 编译前将 INI 选项硬编译到 PHP 内(支持多个选项,别名是 `--with-hardcoded-ini`
270271
- `--with-micro-fake-cli`: 在编译 micro 时,让 micro 的 SAPI 伪装为 `cli`(用于兼容一些检查 `PHP_SAPI` 的程序)
271272
- `--disable-opcache-jit`: 禁用 opcache jit(默认启用)

src/SPC/ConsoleApplication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
final class ConsoleApplication extends Application
3232
{
33-
public const VERSION = '2.3.5';
33+
public const VERSION = '2.3.6';
3434

3535
public function __construct()
3636
{

src/SPC/builder/freebsd/BSDBuilder.php

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
8989
$zts_enable = $this->getPHPVersionID() < 80000 ? '--enable-maintainer-zts --disable-zend-signals' : '--enable-zts --disable-zend-signals';
9090
$zts = $this->getOption('enable-zts', false) ? $zts_enable : '';
9191

92+
$config_file_path = $this->getOption('with-config-file-path', false) ?
93+
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
94+
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
95+
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
96+
9297
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
9398
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
9499
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
@@ -109,6 +114,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
109114
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
110115
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
111116
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
117+
$config_file_path .
118+
$config_file_scan_dir .
112119
$json_74 .
113120
$zts .
114121
$this->makeExtensionArgs()

src/SPC/builder/linux/LinuxBuilder.php

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
136136

137137
$config_file_path = $this->getOption('with-config-file-path', false) ?
138138
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
139+
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
140+
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
139141

140142
$enable_cli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
141143
$enable_fpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
@@ -167,6 +169,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
167169
($enable_embed ? '--enable-embed=static ' : '--disable-embed ') .
168170
($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') .
169171
$config_file_path .
172+
$config_file_scan_dir .
170173
$disable_jit .
171174
$json_74 .
172175
$zts .

src/SPC/builder/macos/MacOSBuilder.php

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
139139

140140
$config_file_path = $this->getOption('with-config-file-path', false) ?
141141
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
142+
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
143+
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
142144

143145
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
144146
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
@@ -168,6 +170,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
168170
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
169171
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
170172
$config_file_path .
173+
$config_file_scan_dir .
171174
$json_74 .
172175
$zts .
173176
$this->makeExtensionArgs() . ' ' .

src/SPC/builder/windows/WindowsBuilder.php

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
103103

104104
$micro_w32 = $this->getOption('enable-micro-win32') ? ' --enable-micro-win32=yes' : '';
105105

106+
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
107+
('--with-config-file-scan-dir=' . $this->getOption('with-config-file-scan-dir') . ' ') : '';
108+
106109
cmd()->cd(SOURCE_PATH . '\php-src')
107110
->exec(
108111
"{$this->sdk_prefix} configure.bat --task-args \"" .
@@ -114,6 +117,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
114117
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
115118
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
116119
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
120+
$config_file_scan_dir .
117121
"{$this->makeExtensionArgs()} " .
118122
$zts .
119123
'"'

src/SPC/command/BuildCliCommand.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class BuildCliCommand extends BuildCommand
2222
{
2323
public function configure(): void
2424
{
25+
$isWindows = PHP_OS_FAMILY === 'Windows';
26+
2527
$this->addArgument('extensions', InputArgument::REQUIRED, 'The extensions will be compiled, comma separated');
2628
$this->addOption('with-libs', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
2729
$this->addOption('build-micro', null, null, 'Build micro SAPI');
@@ -32,7 +34,8 @@ public function configure(): void
3234
$this->addOption('no-strip', null, null, 'build without strip, in order to debug and load external extensions');
3335
$this->addOption('enable-zts', null, null, 'enable ZTS support');
3436
$this->addOption('disable-opcache-jit', null, null, 'disable opcache jit');
35-
$this->addOption('with-config-file-path', null, InputOption::VALUE_REQUIRED, 'Set the path in which to look for php.ini');
37+
$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');
38+
$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');
3639
$this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI');
3740
$this->addOption('with-micro-fake-cli', null, null, 'Let phpmicro\'s PHP_SAPI use "cli" instead of "micro"');
3841
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');

0 commit comments

Comments
 (0)