Question

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?

Was it helpful?

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)

OTHER TIPS

After a little more research, I found out that a2dissite is just a shell script, and it basically just calls rm. So, like other responses, I agree that it is safe to do

rm /etc/apache2/sites-enabled/*

ubuntu 12.04lts / ubuntu 16.04lts

You can just do the following [NB: you will may need root permission sudo a2dissite]

a2dissite *

Or

a2dissite

And it will prompt you for the ones you want to do

when you have completely disabled sites restart apache2 server

sudo systemctl restart apache2

or just reload apache configuration without a full restart:

sudo service apache2 reload

To remove the host file just delete it. If you just want to dissable the site, use

sudo a2dissite sitename

Restart apache2

sudo /etc/init.d/apache2 reload

Again to remove (delete)it completely from the system,

sudo rm /etc/apache2/sites-available/sitename

I would also disable it first before deleting the file

You can just delete the symlinks, or move the entire directory away. There is no special database or other metadata besides those links.

I never use 'a2dissite ' and always delete and create the links in /etc/apache2/sites-enabled manually so yes, I'd say it's pretty safe.

Here is my workaround, first type:

# a2dissite (type this command without any argument, it would prompt to ask you choose the next line)

Your choices are: siteA siteB siteC siteD

Which site(s) do you want to disable (wildcards ok)?

Now you just copy all of above list of sites (siteA siteB siteC siteD) and paste into as your answer, then Enter.

The output result would be:

removing dangling symlink /etc/apache2/sites-enabled/siteA.conf
removing dangling symlink /etc/apache2/sites-enabled/siteB.conf
removing dangling symlink /etc/apache2/sites-enabled/siteC.conf
removing dangling symlink /etc/apache2/sites-enabled/siteD.conf

This approach will help us to optional to choose to a long list of names of site should be removed or intact.

you can edit the httpd.conf and delete the include line for the virtual hosts (at the bottom of the file)

Apparently, you can just install the latest Ubuntu ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top