Search code examples
apachevirtualhost

How to disable all apache virtual hosts?


I'm writing a shell script to do some web server configuration. I need to disable all currently active virtual hosts. a2dissite doesn't accept multiple arguments, so I can't do

a2dissite `ls /etc/apache2/sites-enabled`

Should I use find? Is it safe to manually delete the symlinks in /etc/apache2/sites-enabled?


Solution

  • Is your script Debian only? If so, you can safely delete all the symlinks in sites-enabled, that will work as long as all sites have been written correctly, in the sites-available directory.

    For example:

     find /etc/apache2/sites-enabled/ -type l -exec rm -i "{}" \;
    

    will protect you against someone who has actually written a file instead of a symlink in that directory.

    (remove the -i from rm for an automatic script, of course)