shell_exec empty for rebuild_phpconf but not others, works in CLI
I have to run PHP using the CGI handler. In order to not have to run many commands literally all of the time I just use PHP's shell_exec() to run basic commands, clean the results and show the results.
In PHP this results in an empty string:
$v = shell_exec('/usr/local/cpanel/bin/rebuild_phpconf --current');
echo '<pre>v: '.print_r($v,1).'</pre>';
Okay, well I used PuTTY and signed in as the exact same user as PHP:
shell_exec('whoami');
I ran the command(/usr/local/cpanel/bin/rebuild_phpconf --current) in the terminal/CLI via PuTTY and got the expected results.
Other commands in PHP work just fine:
shell_exec('df -h');
So why is this command failing to work in PHP but not directly in the terminal/CLI? I'm using PHP 8.3.
-
So, if I had to guess, this is just a difference between what PHP INI (or FPM config) is in play in the context of php executed via apache versus on the command line. If the configuration loaded via apache (just make a phpinfo page to check versus phpinfo on the CLI) disallows shell_exec via having it listed in the "disable_functions" parameter, then that would explain why this is happening. If so, you'll either have to inquire with your hosting provider to resolve this (or execute what you are looking to execute alternatively -- perhaps the administrator only banned shell_exec and not proc_open, etc.).
0 -
I discovered that PHP is in "chroot jail" and confirmed it when running:
stat -c %i /
Which returned '2'.
Because the topic is related though also entirely different I started a new thread here:
0
Please sign in to leave a comment.
Comments
2 comments