I have written PHP code to execute shell command
<?php exec("phing"); ?>
This is not working at all from browser.
But what I analysed is, it running same command requires "sudo" permission. I am not sure how could I allow my PHP file to execute this commnand as sudo?
Please guide
When executing php, you might not (probably won't be) in any particular directory. Try specifying the absolute path <?php exec("/usr/bin/phing"); ?>
Also, did you mean ping
instead of phing
?
If the webserver has sudo access (a REALLY BAD IDEA) without a password (a REALLY BAD IDEA!!!) to run this command, then you need to change your code to <?php exec("/usr/bin/sudo phing"); ?>
To be able to run sudo, you will need help from the administrator of your computer. I doubt your administrator will allow this, because it's risky to give the webserver sudo access - a lot of work goes into making sure the web server does NOT have any sort of administrator privileges.