PHP exec() not working | php.ini is fine

Hi, I’ve seen few topics but nothing worked.

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

Please help

Hello @alex32 Happy you are here

Have a look at this and see if it will help


php -m | grep pcntl

to confirm php_exec() is enabled

Thanks Josep

I removed pcntl_exec and restarted php

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/”); // no error message, the script doesn’t run
shell_exec (“sudo /my/path/”); // as above
shell_exec (“/my/path/whoami”); // as above

Any clue?

You can change default PHP version in SSH terminal:

$ cp -f /usr/local/lsws/lsphp80/bin/php /usr/bin/

The default php.ini locations


You can run the script e.g.

$ /usr/local/lsws/lsphp80/bin/php shell_exec ("/my/");

If its a permission issue follow this Shell_exec returns permissions error - #5 by chillyplate and see if it works for you

You can add a sink for the command e.g.

$ /usr/local/lsws/lsphp80/bin/php shell_exec("/home/ 2>&1 | tee -a /home/ 2>/dev/null >/dev/null &");

OR better yet write a full script to run it e.g. php script would look like


$command = "run sth here";


place this somewhere in documentroot to run it

Thanks Joseph

I tried as you suggested:

$command ="/usr/local/lsws/lsphp80/bin/php shell_exec($txt_path 2>&1 | tee -a /home/ 2>/dev/null >/dev/null &)";
exec($command );

// result: no created

I moved under // no changes

From php exec() or shell_exec() commands are still not executed.
But with no errors it’s difficult to fix…

// 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 as sudo (above)

Not sure if it makes any difference but my php code runs under Joomla 4 framework.

Please help

Just to be sure verything works , do this:

  1. create a php file at /home/mydomainrunning php80/public_html

  2. add the following code and try to run it

$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";

Thanks for your support Joseph
I finally figured out why I got this problem :slight_smile:
Your test script works fine when called from the browser:

$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
total 16
-rwxrwxrwx  1 cyberpanel cyberpanel  427 Mar  7 13:27
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/ ";   // 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:

> python3 /my/path/

Thanks for your help, really appreciated !

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.