I need to run a sudo command from a PHP script in CentOS 7, but I am getting an error:

sudo: no tty present and no askpass program specified

I have edited my sudoers file with the following lines, as others have advised:

  1. don't require tty:

    Defaults:apache !requiretty

  2. Set no password for apache user:

    apache  ALL=(root) NOPASSWD: /path/to/app, /path/to/app2

(I have double-checked that these paths are correct). My errors persist. Any thoughts?

  • 1
    Is that the only sudoers line for apache? Could it be hitting another rule?
    – Jeff Schaller
    Commented Sep 25, 2018 at 20:17
  • It is the only line, yes Commented Sep 26, 2018 at 8:46
  • You would better find another way of doing that. Apache has another user for security reasons, giving sudo to Apache is a very bad idea. Commented Sep 26, 2018 at 11:39
  • apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this? Commented Sep 26, 2018 at 12:17

1 Answer 1


This line does not give sudo permissions to app and app2:

apache  ALL=(root) NOPASSWD: /path/to/app /path/to/app2

What the above line does is give sudo permissions to run /path/to/app, only if you also pass a single argument to it of /path/to/app2. To specify multiple commands, they need to be separated by a comma:

apache  ALL=(root) NOPASSWD: /path/to/app, /path/to/app2
  • ah, that was just a typo in my post, which I've now changed Commented Sep 26, 2018 at 8:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .