Shell_exec() (0r just exec()) not working on hosted server

if(isset($_POST['clearflags'])){ 
  $output = shell_exec('php clearflags.php'); 
}

The above works fine on my local development server running Debian 10, PHP 7.4 and Apache 2.4.25. clearflags.php is a script that clears various fields in a MySQL database so it’s easy to determine if it properly ran or not.

On my hosted server however (Bluehost), clearflags.php is never executed. My hosting service swears that SAFE MODE is not on in PHP (which is also Version 7.4). If I call from the command line (php clearflags.php), it runs fine.

$output on the hosted server is "Content-type: text/html; charset=UTF-8 " but nothing on my local server where the script is called and runs OK. No entry appears in the error log about this

I’ve also tried using exec() with the same failed result

Running phpinfo() on the hosted server shows that disabled_functions are “no value”

Thoughts?

https://www.supportmyidea.com/executing-php-scripts-on-bluehost-com/ That looks like it might be your problem. On bluehost, the php command processes the script differently - as a web page, whatever that means. Swap to php-cli and see if that works.

As an aside, this looks like a weird way of organising your code. Is there any reason you can’t set up the clearflags.php code as a function, then call that?

Sponsor our Newsletter | Privacy Policy | Terms of Service