• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Unable to run EXEC or SYSTEM PHP functions under Plesk Linux

D

DominicL

Guest
If I run the following script on my Plesk 10.2 linux server:

$c = system("ls");
echo "<br />SYSTEM: ".$c;
$out = array();
$d = exec("ls",$out);
echo "<br />EXEC: ".$d;
echo "<hr /><pre>";
print_r($out);
echo "</pre>";


I get nothing. Well, I get the following:
SYSTEM:
EXEC:
--------------------------------------------------------------------------------

Array
(
)


However, if I run the script on local WAMP server, it works fine (obviously changing ls for dir).

I have checked on the web, and the general opinion is that I am running in safe mode. However, checking phpinfo on the plesk server reveals the following:

Setting - Local - Master

safe_mode - Off - On
safe_mode_exec_dir - no value - no value
safe_mode_gid - Off - Off
safe_mode_include_dir -no value - no value

So safe mode is definately off.

Does anybody know why EXEC or SYSTEM don't work?

Incidently, the reason I want to use EXEC is because I want to let users do table backups using mysqldump.
 
Last edited by a moderator:
Can I take it from the lack of response that nobody else has a problem in running the PHP EXEC function under Plesk Panel 10?
 
I know this is a couple months later, but I came across your question while searching for the solution to my own problem. Check your settings against the output of phpinfo(). In my case, safe_mode is being forcefully turned on despite my settings to the contrary.

This "bug" of mine may be caused by my usage of a subdomain or it may be wider than that -- I'm trying to figure it out.
 
How to detect the problem

A program cannot executed due to a lot of possibilities, and in some cases you will not know why without redirecting the error channel. exec() only captures the STDOUT, so if an error occurs, you will not get the message. So try to redirect STDERR to STDOUT to get them both. Also would help to check the exit code of the command to see if it was successful.

Try this code to see the error, where $command is the command you want to exec:

$c = system($command." 2>&1");
echo "<br />SYSTEM: ".$c;

$out = array();
exec($command." 2>&1",$out,$exitcode);
echo "<br />EXEC: ( exitcode : $exitcode )";
echo "<hr /><pre>";
print_r($out);
echo "</pre>";

Solution found at http://www.tek-tips.com/viewthread.cfm?qid=1662412.
 
Back
Top