Skip to content

Instantly share code, notes, and snippets.

@ribeiroevandro
Last active December 21, 2015 01:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ribeiroevandro/6225234 to your computer and use it in GitHub Desktop.
Save ribeiroevandro/6225234 to your computer and use it in GitHub Desktop.
Script for creating Virtual Servers On Apache
#!/bin/bash
# Script for creating Virtual Servers On Apache
# Check for the correct parameters
if [ $# -eq 0 ]; then
echo 'Você precisa passar o domínio a ser criado como parâmetro'
echo 'Uso: create-site your-domain.com'
exit 0
fi
# Assign Variables
SITE=$1
# Create the Directory which will contain your Virtual Site
if [ ! -d /var/www/$SITE ]; then
mkdir /var/www/$SITE
fi
echo "Criado VHost! ✓ "
# Create the Config file for your virtual site
echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$SITE.dev.conf
echo " ServerAdmin webmaster@localhost" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " DocumentRoot /var/www/$SITE" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " ServerName $SITE.dev" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " <Directory "/var/www/$SITE">" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " Options Indexes FollowSymLinks MultiViews" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " AllowOverride All" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " Order allow,deny" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " Allow from all" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " </Directory>" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " ErrorLog /var/log/$SITE-error.log" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " LogLevel warn" >> /etc/apache2/sites-available/$SITE.dev.conf
echo " CustomLog /var/log/$SITE-access.log combined" >> /etc/apache2/sites-available/$SITE.dev.conf
echo "</VirtualHost>" >> /etc/apache2/sites-available/$SITE.dev.conf
echo "Criado Link simbólico! ✓ "
# Create the Sym Link to enable your Virtual Site
if [ ! -L /etc/apache2/sites-enabled/$SITE.dev.conf ]; then
ln -s /etc/apache2/sites-available/$SITE.dev.conf /etc/apache2/sites-enabled/
fi
echo "Incluído domínio no arquivo de hosts! ✓ "
# Include server name (domain name) and any aliases in file hosts
echo "127.0.0.1 $SITE.dev" >> /etc/hosts
echo "" >> /etc/hosts
echo "Reiniciando o apache! ✓ "
# Reload in service the apache2
service apache2 reload
echo "Alterando usuário e grupo do apache! ✓ "
# Change the user and group of the folder in apache
chown -Rf www-data:www-data /var/www/$SITE
- Atualizando o script incluído ".dev.conf" para que funcione corretamente o virtual host no apache 4.2.7.
- Incluindo checagem dos passos realizados.
- Incluindo opções no arquivo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment