The Apache’s user
www-data need to be granted privileges to execute certain applications using
- Run the command
sudo visudo. Actually we want to edit the file in
etc/sudoers.To do that, by using
sudo visudo in terminal ,it duplicate(temp)
sudoers file to edit.
- At the end of the file, add the following ex:-if we want to use command for
restart smokeping and
php command for another action in your question,
www-data ALL=NOPASSWD: /etc/init.d/smokeping/restart, usr/bin/php
(This is assuming that you wish to run
php commands using super user (root) privileges.And you use
php command in
usr/bin/ path )
However, if you wish to run every application using super user privileges, then add the following instead of what’s above.You might not want to do that, not for
ALL commands, very dangerous.
www-data ALL=NOPASSWD: ALL
3.After edit the sudoers file(by
visudo we edit the temp file of
sudoers so save and quit temp file(visudo) to write in
4.That’s it, now use
shell_exec in the following manner inside your
xxx.phpscript.keep remember to use
sudo before the command use in the php script.
exec ("sudo /etc/init.d/smokeping restart 2>&1");
shell_exec("sudo php -v");
So in your problem,add the commands that you wish to use in to the
step no (2.) as I add and change your php script as what you want.
here is the same problem as yours http://stackoverflow.com/a/22953339/1862107