how do I exectute shell commands from a php script?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tarzen5001
Forum Newbie
Posts: 2
Joined: Tue Apr 25, 2006 8:01 pm

how do I exectute shell commands from a php script?

Post by tarzen5001 »

Im trying to execute a shell command from a php script.

the php script is in /var/www/kernel_web

#install.php
<?php
exec("sudo -u root /var/www/./test.sh");
?>

commands like ls works but anything with a sudo wouldnt work
i have already edited to etc/sudoers file so it wouldnt ask for password.

%admin ALL=(ALL) NOPASSWD:ALL

the error log on var/log/apache2/error.log reports that the command requires a password.
tarzen5001
Forum Newbie
Posts: 2
Joined: Tue Apr 25, 2006 8:01 pm

Solved!!!

Post by tarzen5001 »

Basically I was forgetting that the group was NOT www but rather www-data, so the solution is to add to /etc/sudoers (use visudo) the line that allows the group www-data to not be prompted the password prompt with "%www-data ALL=(ALL) NOPASSWD:ALL" added to /etc/sudoers.
Post Reply