Saturday, January 29, 2011

How to add virtual hosts without having to restart apache?

When I read tutorial on how to create /add virtual hosts, the last sentence is always something like:

... now restart apache and you are done!

Now, many (most|all) web hosts have a panel that allow you to create new virtual hosts which are activated almost instantly... and I am sure they didn't restart apache (inconveniencing hundreds of other users) just for my pleasure!

So how to change apache settings / adding virtual hosts, etc. and reloading the new settings without actually restarting the apache server?

  • $ /etc/init.d/httpd reload
    

    This will run a config syntax check and then will make apache reload its config files without interrupting traffic.

    augustin : Oh, cool! I new about the start|stop|restart options, but not about the reload one. Thanks.
    Raphink : Some change also requires `force-reload` rather than `reload`.
    Jason Tan : and make sure you do a: service httpd configtest before your reload - it won't get all config errors, but it catches some.
    ErikA : @Jason, at least on Debian/Ubuntu, the above command runs a config test (and ensures that it exits cleanly) before issuing the `apache2ctl graceful`.
    From ErikA
  • Most linux distros have a small utility called apachectl or apache2ctl, which you can use to just reload the configuration. This will also activate any new virtual hosts. The command you are looking for is apache2ctl graceful

    augustin : Thanks. I'll certainly check them out. How does this compare to the other solution: $ /etc/init.d/httpd reload
    Raphink : @augustin: the init script is a wrapper around `apache2ctl`. I would rather use the init script because it might also launch apache2 as a specific user, which you'd have to know in order to use `apache2ctl`. Trust in the tools that come with your distribution :-)
    From wolfgangsz

0 comments:

Post a Comment