unable to run command as sudo in php (CentOS 7)

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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?










share|improve this question



















  • 1




    Is that the only sudoers line for apache? Could it be hitting another rule?
    – Jeff Schaller
    Sep 25 at 20:17










  • It is the only line, yes
    – Michael Riordan
    Sep 26 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.
    – Rui F Ribeiro
    Sep 26 at 11:39










  • apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this?
    – Diogo Jesus
    Sep 26 at 12:17














up vote
0
down vote

favorite












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?










share|improve this question



















  • 1




    Is that the only sudoers line for apache? Could it be hitting another rule?
    – Jeff Schaller
    Sep 25 at 20:17










  • It is the only line, yes
    – Michael Riordan
    Sep 26 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.
    – Rui F Ribeiro
    Sep 26 at 11:39










  • apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this?
    – Diogo Jesus
    Sep 26 at 12:17












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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?










share|improve this question















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?







centos sudo php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 26 at 8:38

























asked Sep 25 at 19:29









Michael Riordan

386




386







  • 1




    Is that the only sudoers line for apache? Could it be hitting another rule?
    – Jeff Schaller
    Sep 25 at 20:17










  • It is the only line, yes
    – Michael Riordan
    Sep 26 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.
    – Rui F Ribeiro
    Sep 26 at 11:39










  • apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this?
    – Diogo Jesus
    Sep 26 at 12:17












  • 1




    Is that the only sudoers line for apache? Could it be hitting another rule?
    – Jeff Schaller
    Sep 25 at 20:17










  • It is the only line, yes
    – Michael Riordan
    Sep 26 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.
    – Rui F Ribeiro
    Sep 26 at 11:39










  • apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this?
    – Diogo Jesus
    Sep 26 at 12:17







1




1




Is that the only sudoers line for apache? Could it be hitting another rule?
– Jeff Schaller
Sep 25 at 20:17




Is that the only sudoers line for apache? Could it be hitting another rule?
– Jeff Schaller
Sep 25 at 20:17












It is the only line, yes
– Michael Riordan
Sep 26 at 8:46




It is the only line, yes
– Michael Riordan
Sep 26 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.
– Rui F Ribeiro
Sep 26 at 11:39




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.
– Rui F Ribeiro
Sep 26 at 11:39












apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this?
– Diogo Jesus
Sep 26 at 12:17




apache = NOPASSWD: /path/2/app, /path/2/app2 could you try this?
– Diogo Jesus
Sep 26 at 12:17










1 Answer
1






active

oldest

votes

















up vote
1
down vote













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





share|improve this answer




















  • ah, that was just a typo in my post, which I've now changed
    – Michael Riordan
    Sep 26 at 8:40










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471410%2funable-to-run-command-as-sudo-in-php-centos-7%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













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





share|improve this answer




















  • ah, that was just a typo in my post, which I've now changed
    – Michael Riordan
    Sep 26 at 8:40














up vote
1
down vote













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





share|improve this answer




















  • ah, that was just a typo in my post, which I've now changed
    – Michael Riordan
    Sep 26 at 8:40












up vote
1
down vote










up vote
1
down vote









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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 25 at 22:11









jordanm

29.3k27891




29.3k27891











  • ah, that was just a typo in my post, which I've now changed
    – Michael Riordan
    Sep 26 at 8:40
















  • ah, that was just a typo in my post, which I've now changed
    – Michael Riordan
    Sep 26 at 8:40















ah, that was just a typo in my post, which I've now changed
– Michael Riordan
Sep 26 at 8:40




ah, that was just a typo in my post, which I've now changed
– Michael Riordan
Sep 26 at 8:40

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471410%2funable-to-run-command-as-sudo-in-php-centos-7%23new-answer', 'question_page');

);

Post as a guest













































































XrwlVjocUvqZ,TuD9G UyLtU aGcckwSn,VH5euES5RK7x6KEDDTZ,u,W7
CvqIkCXJ ATKTZtD9cUUcS

Popular posts from this blog

How to check contact read email or not when send email to Individual?

How many registers does an x86_64 CPU actually have?

Displaying single band from multi-band raster using QGIS