PHP - Run a command using exec

by
Jeremy Canfield |
Updated: October 11 2022
| PHP articles
exec can be used to run a command on the PHP server. For example, if the PHP server is a Linux system, exec could be used to run Linux command whoami.
<?php
exec('whoami', $output, $return_code);
print_r($output);
echo "Return Code = $return_code <br>";
?>
Which should return something like this.
Array ()
Return Code = 0
Did you find this article helpful?
If so, consider buying me a coffee over at