Skip to content

Instantly share code, notes, and snippets.

@jnpkr
Last active December 12, 2015 09:49
Show Gist options
  • Save jnpkr/4754330 to your computer and use it in GitHub Desktop.
Save jnpkr/4754330 to your computer and use it in GitHub Desktop.
Create new Apache virtualhost on Ubuntu 10.0.4 (Lucid)
#!/bin/bash
#! Shell script to add domains/websites in apache
echo "Enter the domain:"
read domain
mkdir -p "/srv/www/$domain/public_html"
mkdir "/srv/www/$domain/logs"
echo "<VirtualHost *:80>" >> "/etc/apache2/sites-available/$domain"
echo " ServerAdmin webmaster@$domain" >> "/etc/apache2/sites-available/$domain"
echo " ServerName $domain" >> "/etc/apache2/sites-available/$domain"
echo " ServerAlias www.$domain" >> "/etc/apache2/sites-available/$domain"
echo " DocumentRoot /srv/www/$domain/public_html/" >> "/etc/apache2/sites-available/$domain"
echo " ErrorLog /srv/www/$domain/logs/error.log" >> "/etc/apache2/sites-available/$domain"
echo " CustomLog /srv/www/$domain/logs/access.log combined" >> "/etc/apache2/sites-available/$domain"
echo "</VirtualHost>" >> "/etc/apache2/sites-available/$domain"
sudo a2ensite "$domain"
sudo /etc/init.d/apache2 reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment