Impossible to call a bash file with shell_exec with PHP

I am managing a Rocky Linux 8 server.
I would like to be able to execute bash files from a webpage.

Here is the information about the structure:

  • The PHP file is in /var/www/mywebsite.com/index.php with (apache:apache CH644)
  • My bash file is in /root/test.sh (root:root CH755)
  • In php.ini file shell_exec has been removed from disable_functions

Here is the content of test.sh file:

#!/bin/bash echo 'hello';

1/ From my console as root user, when I execute “/root/test.sh”, it’s working fine!

2/ From my PHP file, if I run the following code, it’s working too.

$test = shell_exec('date'); echo $test;

3/ From my PHP file, if I run the following code, it’s not working :

$test = shell_exec('/root/test.sh'); or $test = shell_exec('sh /root/test.sh'); or $test = shell_exec('/usr/bin/sh /root/test.sh'); echo $test;

It’s not working and it is so frustrating…

I have been searching for hours and I do not find any solution.
Would you please help me solve this issue.
Maybe is the Apache Configuration that is wrong…

Thank you so much!