#!/usr/bin/python import os import sys import subprocess def create_vhost(site_name, site_folder): conf_string = """ ServerName {0} ServerAdmin webmaster@localhost DocumentRoot {1} """.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])