Skip to content

Instantly share code, notes, and snippets.

@asyndrige
Last active November 2, 2015 10:03
Show Gist options
  • Save asyndrige/0fcf8f7432b5e310e942 to your computer and use it in GitHub Desktop.
Save asyndrige/0fcf8f7432b5e310e942 to your computer and use it in GitHub Desktop.
#!/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