1

how to run bash script from php with sudo

index.php :

<?php
$arg;
exec("sudo /var/www/script", $arg);
?>

script :

!#/bin/bash
echo YOUR ARG IS $1;
sudoers www-data ALL=NOPASSWD /var/www/my 
chmod 755 /var/www/my 

1 Answer 1

1

Firstly, you can't sudo it directly like that. So you have to change some configurations in sudoers file.

Run sudo visudo in console, add the following line at the end of file

nobody ALL = NOPASSWD: /var/www/script

P.S.: It's a security risk to use your script like that which would sometime perform breach in data security in a great extent so my suggestion is don't call your script like that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.