My php.ini doesn’t block exec() or shell_exec(), but yet the shell command from php doesn’t execute. It works only from the terminal.
I gave folder permissions to user: cyberpanel: still not working
php -m | grep pcntl // this returns: pcntl
php --version // returns 8.2 but the version I’m using for the website running exec() is 8.0
Running the shell-command as sudo: didn’t work either.
sudo chmod a+rwx /my/path/ // granted permission to everyone
exec (“sudo /my/path/script.py”); // no error message, the script doesn’t run
shell_exec (“sudo /my/path/script.py”); // as above
shell_exec (“/my/path/whoami”); // as above
From php exec() or shell_exec() commands are still not executed.
But with no errors it’s difficult to fix…
shell_exec(‘whoami’);
// doesn’t return anything so I can’t add that user to sudoers. But I don’t think it makes any difference as I already tried to run test.py as sudo (above)
Not sure if it makes any difference but my php code runs under Joomla 4 framework.
total 16
-rwxrwxrwx 1 cyberpanel cyberpanel 427 Mar 7 13:27 test.py
drwxrwxr-x 21 bobi5464 bobi5464 4096 Mar 7 16:43 ..
drwxrwxr-x 2 bobi5464 bobi5464 4096 Mar 7 17:59 .
-rw-rw-r-- 1 bobi5464 bobi5464 72 Mar 7 17:59 test.php
But shell_exec() commands doesn’t work unless I shape the string as below:
#!/usr/bin/env python
$command ="/usr/bin/python3 /my/path/test.py "; // this is !crucial
$out = shell_exec($command);
file_put_contents( '/my/path/test.txt', $out); // test.txt is now working
Still I don’t know why the python’s path has to be declared separately in that way, when from terminal the following works just fine: