tags:

views:

182

answers:

1

I'm making a really simple virtual host administrator in my office intranet (on a windows pc) and I'm trying to restart the apache service from php when a new virtual host is created.

But I can't manage to do it, I tried with apache -k restart, httpd -k restart with the system, shell_exec, exec passthru; I also tried using a batch file and executing it from php commands but no avail. There are no errors, the command just doesn't get executed

The only way I managed to stop (but not to restart) the service was by making NET STOP Apache2.2, and making a batch file with:

@echo off
NET STOP Apache2.2
NET START Apache2.2

didn't work either.

Any idea why? I'm clueless here. Other commands get executed just fine, but for some reason php doesn't want to restart the apache service.

Thanks!

+1  A: 

Trying this from inside a script running under apache will not work or fail miserable, on windows as well as linux.

Usually the user that apache runs as (on any platform) does not have the privileges to restart apache, and it should stay that way.

As mentioned in the link Haim posted, you will probably need some kind of external process or script to restart the server. One way to do this would be to have a script running as a scheduled job check a control file to check when to restart the service.

I'd give more details on how to do it specifically, but I am not a windows expert.

Phillip Whelan