How to call shell script from php that requires SUDO?
Edit the sudoers file (with visudo
) and add a rule that allows the web server user to run the command without a password. For example:
www-data ALL=NOPASSWD: /path/to/script
Executing PHP shell command requires sudo access
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.
Related Topics
How to Make a PHP Soap Call Using the Soapclient Class
Run Process With Realtime Output in PHP
Download File Through an Ajax Call PHP
Search With Comma-Separated Value MySQL
PHP Regex to Get Youtube Video Id
Using a .PHP File to Generate a MySQL Dump
Post Request in Laravel - Error - 419 Sorry, Your Session/ 419 Your Page Has Expired
PHP Warning: PHP Startup: How to Load Dynamic Library
How Create an Array from the Output of an Array Printed With Print_R
Pass JavaScript Array -≫ PHP
Checking If Date Is Weekend PHP
Issue Reading Http Request Body from a Json Post in PHP
Replace the Variable Price Range by the Chosen Variation Price in Woocommerce 3