Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

As part of the signup process on our site, VirtualHost directives get created an added to a config file via PHP, after each VirtualHost is created apache is restarted gracefully so that the new site starts working. The user PHP which runs under (www) was given permission to restart apache in /etc/sudoer and then a php script called exec('/usr/local/bin/sudo /usr/local/sbin/apachectl graceful');

This works perfectly. However we're in the process of moving to a new server and I cant get this working at all on the new setup

Ive added the following line to /etc/sudoers

apache ALL= NOPASSWD: /usr/sbin/apachectl graceful

and then our PHP script calls:

exec('/usr/bin/sudo /usr/sbin/apachectl graceful');

If I enable shell access for the apache user and login I can run 'sudo /usr/sbin/apachectl graceful' perfectly fine, its just when we call it from PHP it doesnt work.

Has anybody got any ideas? Thanks.

On our old FreeBSD server we were running Apache 1.3.x and PHP 4.4

Our new server is CentOS 5.4 w/ Apache 2.2.x and PHP 5.3.2

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

In the sudoers file (use visudo), below the extant defaults line, add:

defaults:www !requiretty

Actually, are you sure it's running as the "www" user? The default for CentOS is "apache". A little script to try:

<?php print system("whoami");?>

If it's not "www", just replace the "www" bit in sudoers, above.

share|improve this answer
    
This did the trick, Adding: Defaults:apache !requiretty to /etc/sudoers. Thank you very much! –  James Jul 14 '10 at 15:10
    
As I recall, figuring out something very similar to this took about four hours and culminated in some work in gdb. So... yeah. The more people I can help solve this problem, the more I amortize that effort. ;) –  BMDan Jul 15 '10 at 21:41
add comment

Can you try with shell_exec ?

share|improve this answer
    
I've just tried shell_exec() exactly the same, no output returned either if that makes any difference. PHP is definitely running under the apache user, ive just tried shell_exec('whoami'). –  James Jul 14 '10 at 15:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.