0

If I add a new Apache site at /etc/apache2/sites-enabled/newsite.conf, how to I load that new configuration without bringing down any other sites currently being hosted by Apache?

As far as I know, sudo apachectl graceful and sudo service apache2 restart and sudo service apache2 reload all cause a brief outage to all sites, with the outage being shorter for reload.

Cerin
  • 3,600
  • 19
  • 61
  • 79
  • apache2ctl has a config test – djdomi Jan 18 '22 at 16:49
  • @djdomi But that doesn't load the new config, right? I want to make the new site hosted and available on the network. – Cerin Jan 18 '22 at 16:51
  • `apachectl graceful` isn't supposed to cause any downtime. `service apache2 reload` internally calls `apachectl graceful` also. – AlexD Jan 18 '22 at 17:39

1 Answers1

1

As per best practice do the following when you add a new website:

  1. Place the config file under /etc/apache2/sites-available in your example newsite.conf.
  2. "Enable" the websitee, run the command: a2ensite newsite
  3. Test your config, run the command apache2ctl configtest
  4. at last reload the config: service apache2 reload

This won't cause an outage for other running websites. You did everything you can to avoid taking down the webserver. apache2ctl configtest will let you know if you did syntax error or a module you want to use in the config is not loaded yet, or the path you defined to an ssl certificate is not valid. Any open session from the clients will stay open. Although you do all necessary steps to avoid taking down the webserver, it can very well happen in case for instance an ssl certificate is not in a correct format, unfortunately apache2ctl configtest can't protect you from that.

I hope my answer helps!

Scream
  • 11
  • 3
  • reload will crash if configtest was failing – djdomi Jan 18 '22 at 18:00
  • @djdomi reload internally calls `apachectl graceful` which, in turn, does `apache configtest` before doing a graceful restart. if `configtest` fails then reload isn't performed, an error message is printed and apache continues running with the old config without a reload. – AlexD Jan 18 '22 at 18:44
  • in my experience of years with apache, reload will crash apache could ve that the behavior has changed but for years it crashed on config test failure – djdomi Jan 18 '22 at 19:08