简体   繁体   中英

run bash script from php exec()

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 

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

PS: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM