-
-
Save renshuki/cdae4b48d42ac9ae77d25f663b90643f to your computer and use it in GitHub Desktop.
Revisions
-
fideloper revised this gist
Apr 25, 2014 . 1 changed file with 21 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,6 +15,7 @@ Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used -d DocumentRoot - i.e. /var/www/yoursite -h Help - Show this menu. -s ServerName - i.e. example.com or sub.example.com -a ServerAlias - i.e. *.example.com or another domain altogether -p File path to the SSL certificate. Directories only, no file name. If using an SSL Certificate, also creates a port :443 vhost as well. This *ASSUMES* a .crt and a .key file exists @@ -41,12 +42,13 @@ cat <<- _EOF_ <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName $ServerName $ServerAlias DocumentRoot $DocumentRoot # Uncomment this to proxy pass to fastcgi # Assumes Apache 2.4 with mod_proxy_fcgi # ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000$DocumentRoot/$1 <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews @@ -61,7 +63,7 @@ cat <<- _EOF_ LogLevel warn CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined #ProxyPassMatch @@ -74,12 +76,13 @@ cat <<- _EOF_ <VirtualHost *:443> ServerAdmin webmaster@localhost ServerName $ServerName $ServerAlias DocumentRoot $DocumentRoot # Uncomment this to proxy pass to fastcgi # Assumes Apache 2.4 with mod_proxy_fcgi # ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000$DocumentRoot/$1 <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews @@ -94,7 +97,7 @@ cat <<- _EOF_ LogLevel warn CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined #ProxyPassMatch SSLEngine on @@ -123,7 +126,7 @@ fi CertPath="" #Parse flags while getopts "d:s:a:p:c:h" OPTION; do case $OPTION in h) show_usage @@ -134,6 +137,9 @@ while getopts "d:s:p:c:h" OPTION; do s) ServerName=$OPTARG ;; a) Alias=$OPTARG ;; p) CertPath=$OPTARG ;; @@ -146,12 +152,19 @@ while getopts "d:s:p:c:h" OPTION; do esac done # If alias is set: if [ "$Alias" != "" ]; then ServerAlias="ServerAlias "$Alias else ServerAlias="" fi # If CertName doesn't get set, set it to ServerName if [ "$CertName" == "" ]; then CertName=$ServerName fi if [ ! -d $DocumentRoot ]; then mkdir -p $DocumentRoot #chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ? fi @@ -170,5 +183,4 @@ else # Enable Site cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf service apache2 reload fi -
fideloper revised this gist
Apr 25, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -61,6 +61,8 @@ cat <<- _EOF_ LogLevel warn CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined #ProxyPassMatch </VirtualHost> @@ -92,6 +94,8 @@ cat <<- _EOF_ LogLevel warn CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined #ProxyPassMatch SSLEngine on -
fideloper revised this gist
Apr 2, 2014 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -43,6 +43,10 @@ cat <<- _EOF_ ServerName $ServerName DocumentRoot $DocumentRoot # Uncomment this to proxy pass to fastcgi # Assumes Apache 2.4 with mod_proxy_fcgi # ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000$DocumentRoot/$1 <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews @@ -71,6 +75,10 @@ cat <<- _EOF_ DocumentRoot $DocumentRoot # Uncomment this to proxy pass to fastcgi # Assumes Apache 2.4 with mod_proxy_fcgi # ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000$DocumentRoot/$1 <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All -
fideloper revised this gist
Feb 18, 2014 . 1 changed file with 26 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,13 +15,18 @@ Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used -d DocumentRoot - i.e. /var/www/yoursite -h Help - Show this menu. -s ServerName - i.e. example.com or sub.example.com -p File path to the SSL certificate. Directories only, no file name. If using an SSL Certificate, also creates a port :443 vhost as well. This *ASSUMES* a .crt and a .key file exists at file path /provided-file-path/your-server-or-cert-name.[crt|key]. Otherwise you can except Apache errors when you reload Apache. Ensure Apache's mod_ssl is enabled via "sudo a2enmod ssl". -c Certificate filename. "xip.io" becomes "xip.io.key" and "xip.io.crt". Example Usage. Serve files from /var/www/xip.io at http(s)://192.168.33.10.xip.io using ssl files from /etc/ssl/xip.io/xip.io.[key|crt] sudo vhost -d /var/www/xip.io -s 192.168.33.10.xip.io -p /etc/ssl/xip.io -c xip.io _EOF_ exit 1 } @@ -82,8 +87,8 @@ cat <<- _EOF_ SSLEngine on SSLCertificateFile $CertPath/$CertName.crt SSLCertificateKeyFile $CertPath/$CertName.key <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars @@ -106,7 +111,7 @@ fi CertPath="" #Parse flags while getopts "d:s:p:c:h" OPTION; do case $OPTION in h) show_usage @@ -117,15 +122,23 @@ while getopts "d:s:c:" OPTION; do s) ServerName=$OPTARG ;; p) CertPath=$OPTARG ;; c) CertName=$OPTARG ;; *) show_usage ;; esac done # If CertName doesn't get set, set it to ServerName if [ "$CertName" == "" ]; then CertName=$ServerName fi if [ ! -d $DocumentRoot ]; then mkdir -p $DocumentRoot #chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ? @@ -137,10 +150,13 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then else create_vhost > /etc/apache2/sites-available/${ServerName}.conf # Add :443 handling if [ "$CertPath" != "" ]; then create_ssl_vhost >> /etc/apache2/sites-available/${ServerName}.conf fi # Enable Site cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf service apache2 reload fi -
fideloper revised this gist
Feb 17, 2014 . 1 changed file with 9 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,9 +15,10 @@ Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used -d DocumentRoot - i.e. /var/www/yoursite -h Help - Show this menu. -s ServerName - i.e. example.com or sub.example.com -c File path to the SSL certificate. Directories only, no file name. If using an SSL Certificate, also creates a port :443 vhost as well. This *ASSUMES* a .crt and a .key file exists at file path /provided-file-path/your-server-name.[crt|key]. Otherwise you can except Apache errors when you reload Apache. Ensure Apache's mod_ssl is enabled via "sudo a2enmod ssl". @@ -81,8 +82,8 @@ cat <<- _EOF_ SSLEngine on SSLCertificateFile $CertPath/$ServerName.crt SSLCertificateKeyFile $CertPath/$ServerName.key <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars @@ -102,10 +103,10 @@ if [ "$#" -lt 4 ]; then show_usage fi CertPath="" #Parse flags while getopts "d:s:c:" OPTION; do case $OPTION in h) show_usage @@ -117,7 +118,7 @@ while getopts "d:s:c" OPTION; do ServerName=$OPTARG ;; c) CertPath=$OPTARG ;; *) show_usage @@ -136,7 +137,7 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then else create_vhost > /etc/apache2/sites-available/${ServerName}.conf if [ "$CertPath" != "" ]; then create_ssl_vhost >> /etc/apache2/sites-available/${ServerName}.conf fi -
fideloper revised this gist
Feb 17, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -94,4 +94,4 @@ def create_vhost(documentroot, servername): destLink = '/etc/apache2/sites-enabled/%s.conf' % serverName symlink(srcLink, destLink) system('service apache2 reload') -
fideloper revised this gist
Feb 17, 2014 . 1 changed file with 59 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #! /bin/bash # Run this as sudo! # I move this file to /usr/local/bin/vhost and run command 'vhost' from anywhere, using sudo. # # Show Usage, Output to STDERR @@ -15,6 +15,11 @@ Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used -d DocumentRoot - i.e. /var/www/yoursite -h Help - Show this menu. -s ServerName - i.e. example.com or sub.example.com -c Using an SSL Certificate. Also creates a port :443 vhost as well. This *ASSUMES* a .crt and a .key file exists at file path /etc/ssl/your-server-name/your-server-name.[crt|key]. Otherwise you can except Apache errors when you reload Apache. Ensure Apache's mod_ssl is enabled via "sudo a2enmod ssl". _EOF_ exit 1 @@ -36,8 +41,6 @@ cat <<- _EOF_ <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> @@ -54,13 +57,55 @@ cat <<- _EOF_ _EOF_ } function create_ssl_vhost { cat <<- _EOF_ <VirtualHost *:443> ServerAdmin webmaster@localhost ServerName $ServerName DocumentRoot $DocumentRoot <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined SSLEngine on SSLCertificateFile /etc/ssl/$ServerName/$ServerName.crt SSLCertificateKeyFile /etc/ssl/$ServerName/$ServerName.key <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> BrowserMatch "MSIE [2-6]" \\ nokeepalive ssl-unclean-shutdown \\ downgrade-1.0 force-response-1.0 # MSIE 7 and newer should be able to use keepalive BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown </VirtualHost> _EOF_ } #Sanity Check - are there two arguments with 2 values? if [ "$#" -lt 4 ]; then show_usage fi SSL=0 #Parse flags while getopts "d:s:c" OPTION; do case $OPTION in h) show_usage @@ -71,6 +116,9 @@ while getopts "d:s:" OPTION; do s) ServerName=$OPTARG ;; c) SSL=1 ;; *) show_usage ;; @@ -87,6 +135,11 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then show_usage else create_vhost > /etc/apache2/sites-available/${ServerName}.conf if [ $SSL -gt 0 ]; then create_ssl_vhost >> /etc/apache2/sites-available/${ServerName}.conf fi cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf #Enable site service apache2 reload #Optional implementation fi -
fideloper revised this gist
Jan 26, 2014 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ from os.path import exists from os import makedirs from os import symlink from os import system import getopt # @@ -35,7 +36,8 @@ def create_vhost(documentroot, servername): Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Order allow,deny Allow from all Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/%s-error.log @@ -91,4 +93,5 @@ def create_vhost(documentroot, servername): srcLink = '/etc/apache2/sites-available/%s.conf' % serverName destLink = '/etc/apache2/sites-enabled/%s.conf' % serverName symlink(srcLink, destLink) os.system('service apache2 reload') -
fideloper revised this gist
Oct 18, 2013 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,8 @@ cat <<- _EOF_ Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Order allow,deny Allow from all Require all granted </Directory> ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log @@ -86,6 +87,6 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then show_usage else create_vhost > /etc/apache2/sites-available/${ServerName}.conf cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf #Enable site service apache2 reload #Optional implementation fi -
fideloper revised this gist
Aug 5, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -86,6 +86,6 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then show_usage else create_vhost > /etc/apache2/sites-available/${ServerName}.conf a2ensite /etc/apache2/sites-available/${ServerName}.conf #Enable site service apache2 reload #Optional implementation fi -
fideloper revised this gist
Aug 2, 2013 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ def create_vhost(documentroot, servername): DocumentRoot %s <Directory %s> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Order allow,deny allow from all 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 charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ cat <<- _EOF_ DocumentRoot $DocumentRoot <Directory $DocumentRoot> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Order allow,deny allow from all @@ -86,6 +86,6 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then show_usage else create_vhost > /etc/apache2/sites-available/${ServerName}.conf a2ensite /etc/apache2/sites-available/${ServerName} #Enable site service apache2 reload #Optional implementation fi -
fideloper revised this gist
Nov 25, 2012 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def create_vhost(documentroot, servername): DocumentRoot %s <Directory %s> Options -Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny 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 charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ cat <<- _EOF_ DocumentRoot $DocumentRoot <Directory $DocumentRoot> Options -Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny -
fideloper revised this gist
Jun 11, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -40,13 +40,13 @@ cat <<- _EOF_ allow from all </Directory> ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined </VirtualHost> -
fideloper revised this gist
Jun 10, 2012 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ def create_vhost(documentroot, servername): DocumentRoot %s <Directory %s/> Options -Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all 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 charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ cat <<- _EOF_ DocumentRoot $DocumentRoot <Directory $DocumentRoot/> Options -Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all -
fideloper revised this gist
Jun 2, 2012 . No changes.There are no files selected for viewing
-
Chris Fidao revised this gist
May 17, 2012 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ #! /usr/bin/python from sys import argv from os.path import exists from os import makedirs @@ -86,7 +84,7 @@ def create_vhost(documentroot, servername): print 'vHost already exists. Aborting' show_usage() else: target = open('/etc/apache2/sites-available/%s.conf' % serverName, 'w') target.write(create_vhost(documentRoot, serverName)) target.close() -
Chris Fidao revised this gist
May 17, 2012 . No changes.There are no files selected for viewing
-
Chris Fidao revised this gist
May 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #! /bin/bash # May need to run this as sudo! # I have it in /usr/local/bin and run command 'vhost' from anywhere, using sudo. # -
Chris Fidao revised this gist
May 17, 2012 . 1 changed file with 96 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,96 @@ #! /usr/bin/python # ***NOT YET TESTED*** PYTHON VERSION from sys import argv from os.path import exists from os import makedirs from os import symlink import getopt # # Show Usage, Output to STDERR # def show_usage(): print """ Create a new vHost in Ubuntu Server Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used -d DocumentRoot - i.e. /var/www/yoursite -h Help - Show this menu. -s ServerName - i.e. example.com or sub.example.com """ exit(1) # # Output vHost skeleton, fill with userinput # To be outputted into new file # def create_vhost(documentroot, servername): out = """<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName %s DocumentRoot %s <Directory %s/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/%s-error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/%s-access.log combined </VirtualHost>""" % (servername, documentroot, documentroot, servername, servername) return out #Parse flags, fancy python way. Long options also! try: opts, args = getopt.getopt(argv[1:], "hd:s:", ["help", "document-root=", 'server-name=']) except getopt.GetoptError, err: print str(err) show_usage() #Sanity check - make sure there are arguments if opts.__len__() == 0: show_usage() documentRoot = None serverName = None #Get values from flags for option, value in opts: if option in ('-h', '--help'): show_usage() elif option in ('-d', '--document-root'): documentRoot = value elif option in ('-s', '--server-name'): serverName = value else: print "Unknown parameter used" show_usage() if exists(documentRoot) == False: makedirs(documentRoot, 0755) #chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ? #from pwd import getpwnam -> inspect: getpwnam('someuser') if exists('%s/%s.conf' % (documentRoot, serverName)): print 'vHost already exists. Aborting' show_usage() else: target = open('/etc/apache2/sites-available/%r.conf' % serverName) target.write(create_vhost(documentRoot, serverName)) target.close() srcLink = '/etc/apache2/sites-available/%s.conf' % serverName destLink = '/etc/apache2/sites-enabled/%s.conf' % serverName symlink(srcLink, destLink) #service apache2 reload #Optional implementation -> from os import system -> os.system('service apache2 reload') -
Chris Fidao revised this gist
May 16, 2012 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,8 @@ #! /bin/bash # May need to run this as sudo # I have it in /usr/local/bin and run command 'vhost' from anywhere, using sudo. # # Show Usage, Output to STDERR # @@ -84,4 +87,5 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then else create_vhost > /etc/apache2/sites-available/${ServerName}.conf ln -s /etc/apache2/sites-available/${ServerName}.conf /etc/apache2/sites-enabled/${ServerName}.conf #service apache2 reload #Optional implementation fi -
Chris Fidao revised this gist
May 16, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -75,6 +75,7 @@ done if [ ! -d $DocumentRoot ]; then mkdir -p $DocumentRoot #chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ? fi if [ -f "$DocumentRoot/$ServerName.conf" ]; then -
Chris Fidao revised this gist
May 16, 2012 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -50,8 +50,8 @@ cat <<- _EOF_ _EOF_ } #Sanity Check - are there two arguments with 2 values? if [ $# -ne 4 ]; then show_usage fi @@ -70,7 +70,6 @@ while getopts "d:s:" OPTION; do *) show_usage ;; esac done @@ -82,6 +81,6 @@ if [ -f "$DocumentRoot/$ServerName.conf" ]; then echo 'vHost already exists. Aborting' show_usage else create_vhost > /etc/apache2/sites-available/${ServerName}.conf ln -s /etc/apache2/sites-available/${ServerName}.conf /etc/apache2/sites-enabled/${ServerName}.conf fi -
Chris Fidao created this gist
May 16, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,87 @@ #! /bin/bash # # Show Usage, Output to STDERR # function show_usage { cat <<- _EOF_ Create a new vHost in Ubuntu Server Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used -d DocumentRoot - i.e. /var/www/yoursite -h Help - Show this menu. -s ServerName - i.e. example.com or sub.example.com _EOF_ exit 1 } # # Output vHost skeleton, fill with userinput # To be outputted into new file # function create_vhost { cat <<- _EOF_ <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName $ServerName DocumentRoot $DocumentRoot <Directory $DocumentRoot/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/$ServerName-error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/$ServerName-access.log combined </VirtualHost> _EOF_ } #Sanity Check - are there two arguments? if [ $# -ne 2 ]; then show_usage fi #Parse flags while getopts "d:s:" OPTION; do case $OPTION in h) show_usage ;; d) DocumentRoot=$OPTARG ;; s) ServerName=$OPTARG ;; *) show_usage ;; ;; esac done if [ ! -d $DocumentRoot ]; then mkdir -p $DocumentRoot fi if [ -f "$DocumentRoot/$ServerName.conf" ]; then echo 'vHost already exists. Aborting' show_usage else make_vhost > /etc/apache2/sites-available/${ServerName}.conf ln -s /etc/apache2/sites-available/${ServerName}.conf /etc/apache2/sites-enabled/${ServerName}.conf fi