When you execute linux command in PHP functions like exec(), system() or shell_exec() there might be a problem in accessing certain files. Here the commands are executed by Apache and the user which executes it is www-data. This user does not have root access and if you use sudo, it will ask for password. This can be solved by editing the /etc/sudoers file.
It is recommended to take a backup before editing this file. Go to shell prompt and type:
visudo
Add the line below to the file and save.
www-data ALL=(ALL) NOPASSWD: ALL
Restart Apache2 using
/etc/init.d/apache2 restart