Skip to content

Instantly share code, notes, and snippets.

@tiagopassinato
Last active September 21, 2015 21:20
Show Gist options
  • Save tiagopassinato/8e9c5a648109688aab67 to your computer and use it in GitHub Desktop.
Save tiagopassinato/8e9c5a648109688aab67 to your computer and use it in GitHub Desktop.
Quickly add apache vhost
#!/bin/bash
echo "Creating VHOST $1"
echo "Creating folder /home/sites/$1"
mkdir /home/sites/$1
echo "Log dir & Public HTML"
mkdir /home/sites/$1/logs
mkdir /home/sites/$1/htdocs
mkdir /home/sites/$1/cgi-bin
echo "VHOST Files"
cp modelo_vhost /etc/apache2/sites-available/$1
sed -i -- "s/{{host}}/$1/g" /etc/apache2/sites-available/$1
echo "default index.html"
echo "It Works" > /home/sites/$1/htdocs/index.html
echo "Permissions"
chown -R username:www-data /home/sites/$1
echo "Restart Apache"
a2ensite $1
apache2ctl restart
@tiagopassinato
Copy link
Author

# modelo_vhost
#  {{host}}
#
<VirtualHost *:80>
        ServerAdmin jornal@pagina3.com.br
        ServerName  {{host}}
        ServerAlias www.{{host}}

        # Indexes + Directory Root.
        DirectoryIndex index.php index.html index.htm
        DocumentRoot /home/sites/{{host}}/htdocs/

        # CGI Directory
        ScriptAlias /cgi-bin/ /home/sites/{{host}}/cgi-bin/
        <Location /cgi-bin>
                Options +ExecCGI
        </Location>

        # Logfiles
        ErrorLog  /home/sites/{{host}}/logs/error.log
        CustomLog /home/sites/{{host}}/logs/access.log combined
</VirtualHost>

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