frankenphp
frankenphp copied to clipboard
Configure `php.ini` path with environment variables
What happened?
Currently, it's possible to configure the directory for additional .ini
files with PHP_INI_SCAN_DIR
environment variable in the standalone FrankenPHP binary, but it's not possible to configure the php.ini
path with any environment variable.
Maybe PHP_INI_DIR
and PHP_INI_DIR/conf.d
are appropriate defaults for PHP configuration file path and additional .ini
files as they are default values in PHP official base images.
Build Type
Standalone binary
Worker Mode
Yes
Operating System
GNU/Linux
CPU Architecture
x86_64
Relevant log output
No response
they are default values in PHP official base images.
Not to be pedantic or anything, but PHP doesn't have any official images. I think you are referring to the community images in the _
library on Docker Hub, and they are the base images here.
but it's not possible to configure the php.ini path with any environment variable.
I don't think I understand. Can't you put the php.ini
file in the PHP_INI_SCAN_DIR
folder?
The PHP_INI_SCAN_DIR
additional configuration path is utilized for extension-specific ini
files as well as for customizing default values in php.ini-production
. When both the main ini
file and custom ini
files are placed in the same directory, ambiguity arises regarding which values are being selected.
php.ini-production
is not used anywhere. It's a template. You still have to copy it to php.ini
or tell php to load it.
There isn't any ambiguity on what options are applied and what order:
From https://www.php.net/manual/en/configuration.file.php:
It is possible to configure PHP to scan for .ini files in a directory after reading php.ini. This can be done at compile time by setting the --with-config-file-scan-dir option. The scan directory can then be overridden at run time by setting the PHP_INI_SCAN_DIR environment variable.
It is possible to scan multiple directories by separating them with the platform-specific path separator (; on Windows, NetWare and RISC OS; : on all other platforms; the value PHP is using is available as the PATH_SEPARATOR constant). If a blank directory is given in PHP_INI_SCAN_DIR, PHP will also scan the directory given at compile time via --with-config-file-scan-dir.
Within each directory, PHP will scan all files ending in .ini in alphabetical order. A list of the files that were loaded, and in what order, is available by calling php_ini_scanned_files(), or by running PHP with the --ini option.
There are no rules as to what is in the ini files, they are simply applied in alphabetical order.
I have a non standard Linux and I needed to add a php.ini file in /lib directory in order to connect to MariaDB again with a non standard path. I added only one line:
mysqli.default_socket = /var/run/mysqld/mysqld.sock
And we are all good.
@dunglas I just realized PHP_INI_SCAN_DIR overrides the default ini files. In my CI, I copy the production ini file into php.ini and then install some extensions. I had an impression with PHP_INI_SCAN_DIR I could provide additional configuration (host specific) but turns out when I use PHP_INI_SCAN_DIR, it discards the original php.ini I copied!
Same problem here. I had the impressions that PHP_INI_SCAN_DIR could be used to provide additional configuration files without overwriting the original php.ini but unfortunately that's what it looks it does.
I had the impressions that PHP_INI_SCAN_DIR could be used to provide additional configuration files without overwriting the original php.ini but unfortunately that's what it looks it does.
It should be possible, quoting the doc:
If a blank directory is given in PHP_INI_SCAN_DIR, PHP will also scan the directory given at compile time via --with-config-file-scan-dir.
e.g. PHP_INI_SCAN_DIR=:/another/dir/containint/ini/files
(note the :
, which should be ;
on Windows)
We'll stick with upstream defaults here. Please send a message on PHP internals if you want PHP to change their defaults.