Skip to content

Instantly share code, notes, and snippets.

@omgmog
Created September 30, 2013 19:46
Show Gist options
  • Save omgmog/6769123 to your computer and use it in GitHub Desktop.
Save omgmog/6769123 to your computer and use it in GitHub Desktop.
Bash function to create Apache site files magically.
function makeconf {
primary=${1}
conffile="${conf}/${primary}.conf"
echo "<VirtualHost *:80>" >> "${conffile}"
echo " Servername ${primary}" >> "${conffile}"
echo " ServerAlias www.${primary}" >> "${conffile}"
shift
for i; do
cat >> "${conffile}" <<EOL
ServerAlias ${i}
ServerAlias www.${i}
EOL
done
echo " DocumentRoot /srv/www/${primary}" >> "${conffile}"
echo "</VirtualHost>" >> "${conffile}"
}
@omgmog
Copy link
Author

omgmog commented Sep 30, 2013

Usage: makeconf maindomain [alternatedomain_1 alternatedomain_2 alternatedomain_n]

This script assume that you have a variable called conf that points to the location of your Apache site files (such as /etc/apache2/sites-enabled)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment