Last active
November 2, 2015 10:03
-
-
Save asyndrige/0fcf8f7432b5e310e942 to your computer and use it in GitHub Desktop.
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 | |
import os | |
import sys | |
import subprocess | |
def create_vhost(site_name, site_folder): | |
conf_string = """<VirtualHost *:80> | |
ServerName {0} | |
ServerAdmin webmaster@localhost | |
DocumentRoot {1} | |
</VirtualHost>""".format(site_name, site_folder) | |
conf = open(os.path.join('/', 'etc', 'apache2', 'sites-available', site_name + '.conf'), 'w') | |
conf.write(conf_string) | |
conf.close() | |
hosts = open(os.path.join('/', 'etc', 'hosts'), 'a') | |
hosts.write('\n127.0.0.1 {0}'.format(site_name)) | |
hosts.close() | |
subprocess.call('a2ensite {}.conf && service apache2 reload'.format(site_name), shell=True) | |
if __name__ == '__main__': | |
create_vhost(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment