Enable all Apache Config Files
Apache, BASH, Sysadmin
Use this BASH script to quickly enable all Apache virtual host configurations.
THis can be handy if for example you are setting up a new development environment.
Background: Enabling Virtual Hosts in Apache 2.4
To set up Apache 2.4 virtual host configurations under Debian/Ubuntu you add a configuration file with a <VirtualHost>
block in the /etc/apache2/sites-available
directory.
Such config files must have the .conf
file extension.
To enable the site, you need to run the a2ensite
script, passing the config filename as an argument. This creates a symlink to the config file in the /etc/apache2/sites-enabled
directory. You then need to reload Apache.
Script
The following script loops through all config files in /etc/apache2/sites-available
and runs a2ensite
. There’s no problem if any site is already enabled, since this does not result in an error.
TL;DR
Copy across the contents of /etc/apache2/sites-available
from the old environment to the new (e.g. with rsync).
Download and run the above script:
Move across /etc/hosts
from the old environment to the new.
References
a2ensite
,a2dissite
Man page
comments powered by Disqus