Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem running PHP EXEC function under Plesk. 1

Status
Not open for further replies.

SunnyByfleet

Technical User
Feb 24, 2003
146
GB
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.
 
Hi

Two things worth to mention, however, not sure they will solve your problem.
SunnyByfleet said:
However, if I run the script on local WAMP server, it works fine (obviously changing ls for dir).
There is a big difference between [tt]ls[/tt] and [tt]dir[/tt] : [tt]ls[/tt] is a standalone executable, [tt]dir[/tt] is a built-in command. So on Windows [tt]cmd[/tt] will always be able to execute [tt]dir[/tt], but on Unix/Linux if $PATH is not set up correctly, [tt]ls[/tt]will not be found. So try to specify the [highlight #fcc]full path[/highlight].

[tt]exec()[/tt] only captures the STDOUT, so if an error occurs, you will not get the message. So try to [highlight #cfc]redirect STDERR to STDOUT[/highlight] to get them both. Also would help to [highlight #ccf]check the exit code[/highlight] of the command to see if it was successful.
PHP:
[navy]$c[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]system[/color][teal]([/teal][green][i]"[highlight #fcc]/usr/bin/[/highlight]ls [highlight #cfc]2>&1[/highlight]"[/i][/green][teal]);[/teal]
[b]echo[/b] [green][i]"<br />SYSTEM: "[/i][/green][teal].[/teal][navy]$c[/navy][teal];[/teal]
[navy]$out[/navy] [teal]=[/teal] [b]array[/b][teal]();[/teal]
[COLOR=darkgoldenrod]exec[/color][teal]([/teal][green][i]"[highlight #fcc]/usr/bin/[/highlight]ls [highlight #cfc]2>&1[/highlight]"[/i][/green][teal],[/teal][navy]$out[/navy][highlight #ccf][teal],[/teal][navy]$exitcode[/navy][teal])[/teal][/highlight][teal];[/teal]
[b]echo[/b] [green][i]"<br />EXEC: [highlight #ccf]( exitcode : $exitcode )[/highlight]"[/i][/green][teal];[/teal]
[b]echo[/b] [green][i]"<hr /><pre>"[/i][/green][teal];[/teal]
[COLOR=darkgoldenrod]print_r[/color][teal]([/teal][navy]$out[/navy][teal]);[/teal]
[b]echo[/b] [green][i]"</pre>"[/i][/green][teal];[/teal]


Feherke.
 
Hi, thanks for the suggestion. I ran your code and get the following:

Code:
SYSTEM: 
EXEC: ( exitcode : 127 )
--------------------------------------------------------------------------------

Array
()

According to a quick google, exitcode 127 means file not found. Is there a linux command I can issue just for testing purposes, which will produce output without running a program?

 
Hi

SunnyByfleet said:
Is there a linux command I can issue just for testing purposes, which will produce output without running a program?
Well, the shells also have built-in commands, but we should know which is you default shell. In meantime I would try [tt]kill -l[/tt]. It is available as built-in command in Bash, Dash and Ksh ( also available as standalone command ) and it lists the signals.


Feherke.
 
Right, I tried kill -l and I get exactly the same result.

However, if I connect by Putty and type that on the command line I do indeed get a list of what I presume are signals.

Perhaps it would help if I explained my environment. I am using a virtual linux server hosted on 1&1. It is running Plesk 10.3, and the linux flavour is CENTOS.

All the commands work if I type them on the commend line. I only get this problem if I use EXEC and the other shell commands.

Its as if there is a setting somewhere explicitly preventing me from running shell commands in php. Yet I have checked safe mode and that is definately off.

I don't know if it helps or not, but this is what the first few lines of phpinfo() say.

Code:
System 

Linux ************************************* SMP Wed Jul 20 19:47:12 MSD 2011 x86_64 



Build Date 

Dec 17 2009 22:43:12 



Configure Command 

'./configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--with-t1lib=/usr' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-system-tzdata' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--disable-json' '--without-pspell' '--disable-wddx' '--without-curl' '--disable-posix' '--disable-sysvmsg' '--disable-sysvshm' '--disable-sysvsem'
 
Hi

SunnyByfleet said:
All the commands work if I type them on the commend line.
Then see what [tt]which ls[/tt] says about where is the [tt]ls[/tt] executable. Then try from the command line :
Code:
[blue]master #[/blue] php -r 'exec("/that/path/to/ls",$o);print_r($o);'


Feherke.
 
Thanks for the help. Its appreciated.

This is what I get. I also tried doing kill that way:

Code:
[root@xxxxxxxx ~]# php -r 'exec("/usr/bin/ls",$o);print_r($o);'
sh: /ls: No such file or directory
Array
(
)
[root@xxxxxxxx ~]# php -r 'exec("kill -l",$o);print_r($o);'
sh: /kill: No such file or directory
Array
(
)
 
Hi

Those paths in the error messages look like [tt]safe_mode[/tt] is On. At least I met such behavior only with [tt]safe_mode[/tt] On and [tt]safe_mode_exec_dir[/tt] unset.

I can think of no other solution than contacting the system administrator.


Feherke.
 
Well I went through the Plesk online help system, and it turns out that there is a page where you can turn safe mode on or off. It seems to operate independently of any ini settings and override what phpinfo thinks the value is set to.

I disabled it there and rerun your test script. Sure enough, lots of stuff appears now.

So, my problem is solved! Thanks for the assistance. You were much more helpful than the Parallels Plesk forum who no suggestions whatsoever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top