exec功能不起作用

<?php
    exec("whoami");

?>

I can be more explicit with the code . Although When I'm trying to call the php file with my browser nothing happens (of course I'm using apache and the whole).

Note : The safe_mode is activated, I'm using php5, php interpreter seems to be nice when running other functions, I'm a ubuntu user.

Then what is wrong?

I think you're looking for the echo function. Executing whoami using the exec function will run the program but show you nothing… you want to spit out the result too.

echo exec("whoami");

You have to echo the output of the exec command somewhere.

PHP documentation for exec function contains the example with whoami, look at the echo.

If possible, turn off safe mode. Safes you lots of headaches.

Otherwise, is the php file owned by the same user that Apache runs as? On Ubuntu, this will usually be www-data.

Try: sudo chown www-data /path/to/you/script.php Then run again.

Right in the docs for exec:

When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.