command php -v is working when I execute simple shell_exec('./script.sh'); but when I use sudo it doesn't work without sudo service stop command is not working.

var_dump(shell_exec('sudo bash ./script.sh')); this command return

sudo: no tty present and no askpass program specified


php -v 

sudo service  apache2 stop



echo shell_exec('./script.sh');
echo shell_exec('sudo bash ./script.sh');  # not working

ls -la

-rwxr-xr-x  1 www-data root    68 Jun 15 02:24 script.sh

**/etc/sudoers **

sudo visudo

apache  ALL=(ALL) NOPASSWD: /bin/bash /var/www/html/script.sh *
www-data  ALL=(ALL) NOPASSWD: /bin/bash /var/www/html/script.sh *


Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:    18.04
Codename:   bionic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.