crazywhalecc / static-php-cli

Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included.
https://static-php.dev
MIT License
1.33k stars 233 forks source link

feat: better default for the php.ini path #553

Closed dunglas closed 1 month ago

dunglas commented 1 month ago

What does this PR do?

By default, the php.ini path is /lib/php.ini. This value is "hardcoded" in PHP but can be changed with configure flags. Most (all?) Linux distributions as well as the official PHP Docker images change this default path to /usr/local/etc/php/php.ini or /etc/php.ini.

This default value is very confusing for end users (see for instance https://github.com/dunglas/frankenphp/issues/1066, it's a recurrent issue we have with FrankenPHP).

Additionally, /lib doesn't even exist by default on Mac, and cannot be created because because the system filesystem is read-only.

This PR aligns the default path to the one used by official Docker images: /usr/local/etc/php/php.ini In addition, it loads all files defined in /usr/local/etc/php/conf.d, as the Docker images do.

It can still be changed easily by end users if needed by overriding SPC_CMD_PREFIX_PHP_CONFIGURE.

crazywhalecc commented 1 month ago

It can still be changed easily by end users if needed by overriding SPC_CMD_PREFIX_PHP_CONFIGURE.

Do you think this happens often? I just found out there is a PR about this before switching to env.ini: #511, which adds command line arguments to specify. I'm not sure which way is more suitable for most people, but we can change the default anyway.

dunglas commented 1 month ago

It could be convenient to provide an easier way to change the path, indeed. Changing the default and adding a new option looks like the best option to me.

crazywhalecc commented 1 month ago

@dunglas I have merged #511 to main, now we can set a default value in this PR.

dunglas commented 1 month ago

@crazywhalecc great! How would you like to proceed? Change the default value in the option definition directly and add a new option to set --with-config-file-scan-dir?

crazywhalecc commented 1 month ago

@crazywhalecc great! How would you like to proceed? Change the default value in the option definition directly and add a new option to set --with-config-file-scan-dir?

TLDR: Yes (only if we use command options).

Off topic: My personal preference for various inputs and variables:

If we use the same default location for macOS, Linux, and FreeBSD, then just use the command option defaults. But if there are different defaults for different systems, it may be better to use env.ini with Internal mutable environment variables directly.

For the --with-config-file-path and --with-config-scan-dir compilation options, they may be edited frequently, but it is also possible that people usually do not need to modify them. This is a fuzzy boundary, so I don't have a clear goal to decide how to deal with these two options.

dunglas commented 1 month ago

Code and docs updated.

I used DeepL for the Chinese translation, it may be totally wrong!