PHP has the exec function. exec('whoami') returns the name of the user who is running the web server (e.g. apache/root/fred). However commands executed with exec() (running as fred) do not behave the same as command executed from a shell (e.g. SSH) session. When you login via SSH, your shell (e.g. bash) instantiates a number of environment variables that shape the context in which you run commands.

