Apache Vhost Creation Script (Gentoo)
November 13th, 2008
Well I decided to post more of the stuff I write even if I think it’s crappy….
So even though there’s probably a dozen like this and it could be a lot nicer, here’s the bash script I wrote to create new subdomains on my web server. Customize to fit your needs.
My apologies for the line wrapping. Fixed
Code below the fold
#!/bin/bash #Copyright (c) 2008 Brian Ortiz "Ortzinator" # #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal #in the Software without restriction, including without limitation the rights #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #copies of the Software, and to permit persons to whom the Software is #furnished to do so, subject to the following conditions: # #The above copyright notice and this permission notice shall be included in #all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #THE SOFTWARE. if [ $# -ne 1 ] then echo "Exactly one argument required" exit 1 fi dir="/var/www/$1" if [ -d "$dir" ] then echo "ERROR: directory '$dir' already exists!" exit 1 else echo "Creating directory '$dir'" mkdir $dir || { echo "Could not create directory '$dir'"; exit 1; } echo "Creating directory '$dir/htdocs'" mkdir $dir/htdocs || { echo "Could not create directory '$dir/htdocs'"; exit 1; } echo "Setting permissions..." chown apache:htdocs $dir || { echo "Error setting permissions for '$dir'"; exit 1; } chown apache:htdocs $dir/htdocs || { echo "Error setting permissions for '$dir/htdocs'"; exit 1; } echo " Placeholder lol " > $dir/htdocs/index.html chown brian:brian $dir/htdocs/index.html || { echo "Error setting permissions for '$dir/htdocs/index.html'"; exit 1; } chmod -R 775 $dir echo " ServerName $1.ortz.org DocumentRoot /var/www/$1/htdocs Allow from all AllowOverride all Order allow,deny " >> /etc/apache2/vhosts.d/00_default_vhost.conf || { echo "Could not add vhost to apache config!"; exit 1; } echo "Restarting apache....." /etc/init.d/apache2 restart || { echo "Could not restart apache!"; exit 1; } echo "All done!" exit 0 fi
EDIT: Check out the improved version Blokkie posted in the comments.
-
Ortzinator
-
Blokkie
-
Blokkie
-
Wang
-
Ortzinator
-
Ortzinator
-
Driusha
-
Driusha





