|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74123 php command-line -c ini settings overridden by default .ini
Submitted: 2017-02-18 09:59 UTC Modified: 2020-04-10 11:54 UTC
From: dean at omnivisiontechnology dot com Assigned:
Status: Suspended Package: PHP options/info functions
PHP Version: 7 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-02-18 09:59 UTC] dean at omnivisiontechnology dot com
The expectation when using PHP from the command line with the -c <my_ini_file> switch is that the settings in <my_ini_file> should take priority over those in the default ini file (as defined by compile-time configuration options --with-config-file-path and --sysconfdir).

Somewhere from moving from v5.x to v7.1.1, this appears to have broken, with the default ini settings overriding the command-line ones.

Test script:
My server's default php.ini is located at /opt/cpanel/ea-php71/root/etc/php.ini
It contains (amongst other things) the lines:

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
error_log = "/home/myusername/public_html/admin/PHP_ERROR_LOG.TXT"

Whereas, I have another .ini located at /home/myusername/DB_BACKUP_SCRIPT/cron_php.ini
That one contains(amongst other things) the lines:

error_reporting = E_ALL
error_log = "/home/myusername/DB_BACKUP_SCRIPT/DB_BACKUP_ERROR_LOG.TXT"

When I execute:  php -c /home/myusername/DB_BACKUP_SCRIPT/cron_php.ini -i
The output includes the following:


System => Linux 3.10.0-327.28.2.el7.x86_64 #1 SMP Wed Aug 3 11:11:39 UTC 2016 x86_64
Build Date => Jan 25 2017 04:20:53
Configure Command =>  './configure'  '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/opt/cpanel/ea-php71/root/usr' '--exec-prefix=/opt/cpanel/ea-php71/root/usr' '--bindir=/opt/cpanel/ea-php71/root/usr/bin' '--sbindir=/opt/cpanel/ea-php71/root/usr/sbin' '--sysconfdir=/opt/cpanel/ea-php71/root/etc' '--datadir=/opt/cpanel/ea-php71/root/usr/share' '--includedir=/opt/cpanel/ea-php71/root/usr/include' '--libdir=/opt/cpanel/ea-php71/root/usr/lib64' '--libexecdir=/opt/cpanel/ea-php71/root/usr/libexec' '--localstatedir=/opt/cpanel/ea-php71/root/usr/var' '--sharedstatedir=/opt/cpanel/ea-php71/root/usr/com' '--mandir=/opt/cpanel/ea-php71/root/usr/share/man' '--infodir=/opt/cpanel/ea-php71/root/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/opt/cpanel/ea-php71/root/etc' '--with-config-file-scan-dir=/opt/cpanel/ea-php71/root/etc/php.d' '--disable-debug' '--with-pic' '--without-pear' '--with-bz2' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-sockets' '--with-kerberos' '--enable-shmop' '--with-libxml-dir=/usr' '--with-system-tzdata' '--with-mhash' '--enable-dtrace' '--libdir=/opt/cpanel/ea-php71/root/usr/lib64/php' '--enable-pcntl' '--enable-opcache' '--disable-opcache-file' '--enable-phpdbg' '--with-imap=shared,/opt/cpanel/ea-php71/root/usr' '--with-imap-ssl' '--enable-mbstring=shared' '--enable-mbregex' '--with-webp-dir=/usr' '--with-gd=shared' '--with-gmp=shared' '--enable-calendar=shared' '--enable-bcmath=shared' '--with-bz2=shared' '--enable-ctype=shared' '--enable-dba=shared' '--with-db4=/usr' '--with-tcadb=/usr' '--enable-exif=shared' '--enable-ftp=shared' '--with-gettext=shared' '--with-iconv=shared' '--enable-sockets=shared' '--enable-tokenizer=shared' '--with-xmlrpc=shared' '--with-ldap=shared' '--with-ldap-sasl' '--enable-mysqlnd=shared' '--with-mysqli=shared,mysqlnd' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--enable-dom=shared' '--with-pgsql=shared' '--enable-simplexml=shared' '--enable-xml=shared' '--enable-wddx=shared' '--with-snmp=shared,/usr' '--enable-soap=shared' '--with-xsl=shared,/usr' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--with-curl=shared,/usr' '--enable-pdo=shared' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-mysql=shared,mysqlnd' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-sqlite3=shared,/usr' '--enable-json=shared' '--enable-zip=shared' '--without-readline' '--with-libedit' '--with-pspell=shared' '--enable-phar=shared' '--with-mcrypt=shared,/opt/cpanel/libmcrypt' '--enable-sysvmsg=shared' '--enable-sysvshm=shared' '--enable-sysvsem=shared' '--enable-shmop=shared' '--enable-posix=shared' '--with-unixODBC=shared,/usr' '--enable-intl=shared' '--with-icu-dir=/usr' '--with-enchant=shared,/usr' '--with-recode=shared,/usr' '--enable-fileinfo=shared' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -fno-strict-aliasing -Wno-pointer-sign' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /opt/cpanel/ea-php71/root/etc
Loaded Configuration File => /home/myusername/DB_BACKUP_SCRIPT/cron_php.ini
PHP Version => 7.1.1

Directive => Local Value => Master Value

error_log => /home/myusername/public_html/admin/PHP_ERROR_LOG.TXT => /home/myusername/public_html/admin/PHP_ERROR_LOG.TXT
error_reporting => 22519 => 22519


Expected result:
As can be seen, the error_log and error_reporting values are those from the default configuration .ini file, and NOT the .ini file passed to the -c command line switch, as they should be.

Before switching to PHP v7.x, this was working correctly.

Note that including the -n command line switch as well fixes this specific problem, but (predictably) causes lots of others (i.e. no DB, graphics, curl, etc. library functions work any more, since they don't get initialized properly).  This shows though, that both .ini files are being processed, just that settings from the wrong one are taking precedence!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-21 12:19 UTC] dean at omnivisiontechnology dot com
-PHP Version: 7.0.16 +PHP Version: 7
 [2017-02-21 12:19 UTC] dean at omnivisiontechnology dot com
I've re-read the docs for how PHP finds .ini files:

...and if I understand correctly, the .ini files specified using --with-config-file-path and --with-config-file-scan-dir are applied *AFTER* the .ini file specified with -c on the command line.

If this is by design, then I guess I'm not reporting a bug, as such.  However, it seems this is very badly designed:  Both to make it useful, and to conform to the principle of least surprise, the -c specified .ini file should be applied *LAST*, so that it overrides all other settings.

As it stands, the -c supplied settings are overridden by all the default .ini files PHP will scan, so (unless you also use -n) the only thing you can do with -c is add new setting options that AREN'T SET AT ALL in any of the default .ini's.

Is this just a really bad historical design choice that can't be changed without breaking backward compatibility, or is there some reason it has to work this way?

And, would it be possible to add another command line option that works just like -c, except that the specified .ini file is processed LAST (and hence overrides ANY other settings?)
 [2020-04-10 11:54 UTC]
-Status: Open +Status: Suspended -Type: Bug +Type: Feature/Change Request
 [2020-04-10 11:54 UTC]
Indeed, not a bug, but rather a feature request.  However, that
feature request requires discussion beyond for what this bug
tracker is suitable.  Therefore, please bring that topic up on the
internals@ mailing list[1].  For the time being, I'm suspending
this ticket.

[1] <>
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Sep 18 18:01:26 2020 UTC