tags:

views:

83

answers:

3

I'm a pretty Huge n00b when it comes to Linux

exec ('whoami', $output, $return);
echo $return;  

// Outputs 127 Which means the command is not executing. I can get it to execute when I root into the server.

Any help would be greatly appreciated!

A: 

If you try this:

<?php
exec('whoami');
?>    

you should be presented with PHP's username.. If you try this:

<?php
exec('whoami', $output, $return);
print_r($output);
?>

you should see that $output is an array containing anything the shell output.

The return value, according to the PHP manual, "return status of the executed command will be written to this variable." - is that what you want?

Andy
What I Really need is to exec pdftk, but any command I try to exec using the PHP function exec() does not work. Even if I try exec('whoami'); it returns 127. I'm thinking this is related to permissions or something, but I have no idea how or what to do to change the permissions to get this fixed.
Gamak
I'm Running CentOS / Apache
Gamak
Running this: exec('whoami', $output, $return);print_r($output); echo $return; Returns This: Array ( ) 127
Gamak
Apparently the 127 code means "file not found". You probably just need to use the absolute path, ( e.g. /usr/local/bin/whoami ).
Andy
A: 

Why not just do something like:

<?php

$var = `whoami`;

echo $var;

?>
peelman
+1  A: 

127 exit status is indicative of a missing command. Perhaps whoami is not on the system or maybe your web server configuration has you jailed in some way or you are being restricted via safe_mode/open_basedir.

To verify you can try running:

exec('which whoami', $output, $return);
print_r($output);
echo $return;

If you are presented with an empty array and a return code of 0, then the whoami executable is currently inaccessible from your web server/PHP setup.

To check safe_mode, open_basedir settings, call phpinfo.

webbiedave