shell_exec from PHP loads wrong ini file?

Operating System & Version
CentOS 7
cPanel & WHM Version
11.104.0.10

Scott Galambos

Well-Known Member
Jul 13, 2016
128
9
68
Canada
cPanel Access Level
Root Administrator
When I run PHP 8.1 from the command line (using a command line script such as #!/usr/local/bin/php81 -q for a script.cgi) it uses the correct INI and only the correct INI.
eg.
core(/temp): php81 -i | grep 'Configuration File'
Configuration File (php.ini) Path => /opt/cpanel/ea-php81/root/etc
Loaded Configuration File => /opt/cpanel/ea-php81/root/etc/php.ini

core(/temp): php81 -i | grep -i 'Additional'
Scan this dir for additional .ini files => /opt/cpanel/ea-php81/root/etc/php.d
Additional .ini files parsed => /opt/cpanel/ea-php81/root/etc/php.d/01-ioncube.ini,

Notice the "Scan this dir for additional .ini files" is only 8.1 which I want. It doesn't try to go all over the place looking for other .ini files.


Now I run this exact command line PHP script using shell_exec from a PHP 7.2 web page.
eg.
shell_exec('/path/script.cgi');

It will work, but imports the wrong PHP file now.
eg.
Configuration File (php.ini) Path => /opt/cpanel/ea-php81/root/etc
Loaded Configuration File => /opt/cpanel/ea-php81/root/etc/php.ini
Scan this dir for additional .ini files => /opt/cpanel/ea-php72/root/etc:/opt/cpanel/ea-php72/root/etc/php.d:.
Additional .ini files parsed => /opt/cpanel/ea-php72/root/etc/php.ini,

Why? What is telling the command line script script.cgi to all of a sudden try to load the ini for 7.2 when run under shell_exec? It runs perfeclty fine at the command line only.
 

Scott Galambos

Well-Known Member
Jul 13, 2016
128
9
68
Canada
cPanel Access Level
Root Administrator
Well, yes, its happening for the domain. But it should only be for the domain. So I go to my PHP 7.2 site at http://mysite.com/whatever.php. That whatever.php has a shell_exec('/path/script.cgi') to run the script. But this shell_exec() has nothing to do with the PHP 7.2 web site or whatever.php. PHP executes a shell to run the script.cgi. The script.cgi is a separate linux process (running the PHP 8.1 command line script script.cgi per its #!/usr/local/bin/php81). script.cgi runs perfectly fine (not loading other ini's) from the actual command line.

So what is different from the actual command line vs shell_exec? Nothing. So why does shell_exec() make the script load other ini files? It doesn't do that from the command line...

Again, shell_exec is not somehow running a PHP interpreter because shell_exec is simply running any agnostic process. It has nothing to do with PHP.