phpubunturootexecutesu

PHP - execute command as root


I'm trying to execute a command as su from php.

When I put the command in terminal or with php /var/www/script.php it works perfect, but when I open script.php through browser it returns - sudo: no tty present and no askpass program specified

Thanks.


Solution

  • According to this:

    ssh does not allocate a tty by default when running a remote command. Without a tty, sudo cannot disable echo when prompting for a password. You can use ssh's "-t" option to force it to allocate a tty. Alternately, if you do not mind your password being echoed to the screen, you can use the "visiblepw" sudoers option to allow this.