Skip to content

Instantly share code, notes, and snippets.

@elioair elioair/createapachesite
Last active Oct 4, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.