Created
June 24, 2010 19:38
-
-
Save wvega/451863 to your computer and use it in GitHub Desktop.
Helper script to quickly setup Apache VirtualHosts on my laptop
This file contains 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
#!/usr/bin/python | |
# | |
# helper script to quickly setup Apache VirtualHosts on my laptop | |
import os | |
import sys | |
HTTPD_CONF_DIR = '/var/www/conf.d' | |
HTTPD_DOCUMENT_ROOT = '/var/www/html' | |
def httpd_conf(domain, src, *args, **kw): | |
root = os.path.join(HTTPD_DOCUMENT_ROOT, domain) | |
conf = open(os.path.join(HTTPD_CONF_DIR, '%s.conf' % domain), 'w+') | |
conf.write('<VirtualHost *:80>\n') | |
conf.write('\tServerName %s\n' % domain) | |
conf.write('\tDocumentRoot %s\n' % root) | |
conf.write('\n') | |
conf.write('\t<Directory %s>\n' % root) | |
conf.write('\t\tOptions FollowSymLinks\n') | |
conf.write('\t\tAllowOverride All\n') | |
conf.write('\t</Directory>\n') | |
conf.write('</VirtualHost>\n') | |
conf.close() | |
try: | |
os.symlink(src, root) | |
except OSError: | |
os.unlink(root) | |
os.symlink(src, root) | |
if __name__ == '__main__': | |
try: | |
httpd_conf(*sys.argv[1:]) | |
except TypeError: | |
print '\nUsage: python httpd-conf.py <domain> <httpd-readable-path-to-project-source>\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment