Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to write a simple php webpage, which lets me reload apach2 config with a single click in the browser. I know, it's a security risk, but I still need it : )

I was able to do so, with a combination of sudo, and exec(), works fine. My only problem is, that when I write out the output of the command "/etc/init.d/apache2 reload", the only thing shows up is "Reloading webserver config: apache2", but the warning message (I put there some missig DocumentRoot dir for testing), won't show up.

It shows up using bash.

First I thought, I use the exec() command in a wrong way, but than I tried to put the output of the apache2 reload command to a file (in bash), and the warning message wasn't there too.

Actually one of the main purpose of the whole thing is to see if something missing after reload, so I need that Warning badly. Any idea, how can i catch that warning message? Or can I find it in some log file?

(I haven't tried it with error message, it might works with those, but I also need to get the warnings.)

share|improve this question
up vote 0 down vote accepted

You could try adding 2>&1 to your command line you execute in your exec statement. This will pipe the error output also to the standard output.

share|improve this answer
THX a lot! It helped! when I use the command: /etc/init.d/apache2 reload >& output.txt everything is there! – develend Jul 21 '10 at 15:33
And it also works in the way, you wrote: <?php $ret = array(); exec("/etc/init.d/apache2 reload 2>&1", $ret); echo implode('', $ret); ?> Thangs a lot again! – develend Jul 21 '10 at 15:38

Your Answer


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