Skip to content

Instantly share code, notes, and snippets.

@elioair
Last active October 4, 2015 00:34
Show Gist options
  • Save elioair/f3b58a7c9ec1a9df38f0 to your computer and use it in GitHub Desktop.
Save elioair/f3b58a7c9ec1a9df38f0 to your computer and use it in GitHub Desktop.
Script to create a website in apache in a LAMP stack.
#!/bin/bash
# permissions
if [ "$(whoami)" != "root" ]; then
echo "Not enough privileges. Run this with sudo."
exit
fi
echo Please, enter website domain [of the form domainname.dev]
read NAME
echo "Creating the configuration file"
echo "<VirtualHost *:80>
DocumentRoot /var/www/html/$NAME
ServerName $NAME
ServerAlias www.$NAME
</VirtualHost>" >> /etc/apache2/sites-available/$NAME.conf
echo "Enabling the site"
a2ensite $NAME
echo "Adding site to hosts file"
printf '127.0.0.1 %s\n' $NAME >> /etc/hosts
echo "Restarting Apache"
service apache2 restart
echo "Complete!"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment