Last active
March 3, 2016 07:17
-
-
Save CodeBrauer/4782afaf41bdfe8a7b5d to your computer and use it in GitHub Desktop.
super simple vhost generator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # super simple vhost generator. | |
| # @CodeBrauer <https://github.com/CodeBrauer> | |
| # v0.2 | |
| if [ -z "$1" ] | |
| then | |
| echo "Error! No domain name given" | |
| exit 1; | |
| fi | |
| echo -ne "\nGenerating vhost '$1'" | |
| VHOST_FILE="/etc/apache2/sites-available/$1.conf" | |
| echo "<VirtualHost *:80> | |
| ServerName $1 | |
| ServerAdmin [email protected] | |
| DocumentRoot /var/www/$1/public_html | |
| LogLevel info | |
| ErrorLog /var/www/$1/logs/error.log | |
| LogFormat \"%h %l %u %t \\\"%r\\\" %>s %b\" common | |
| CustomLog /var/www/$1/logs/access.log combined | |
| php_value open_basedir "/var/www/$1" | |
| </VirtualHost> | |
| " > $VHOST_FILE | |
| echo "Generating dirs..." | |
| mkdir -p /var/www/$1/{logs,public_html} | |
| CONF_CHECK=$(apache2ctl -t 2>&1) | |
| if [[ $CONF_CHECK =~ .*Syntax\ OK.* ]] | |
| then | |
| echo "Configuration is valid. Enabling site..."; | |
| a2ensite $1.conf | |
| echo "Reloading Apache conf..." | |
| service apache2 reload | |
| echo -ne "\nDone!\n" | |
| else | |
| echo "Configuration is invalid! Check the output of 'apache2ctl -t'" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./vhost.sh example.org/etc/apache2/sites-available/public_htmland alogsdir in/var/www/example.org/Tested on Ubuntu 14.04 with Apache 2.4