Dynamically Add Apache Virtual Host with Python
Here's a little python snippet i created to dynamically update my apache config with a new virtual host when a new user signs up to BlogPlot.com. I will be calling this script from Zope via an external method in which i will pass the users domain name from the sign up form.
import string
def add_domain(user_domain):
file = open("/etc/apache2/sites-available/site", "a")
domain = user_domain
template = """
<VirtualHost *:80>
DocumentRoot /www/somedomain.com
ServerName $(domain)s
ServerAlias www.$(domain)s
</VirtualHost>
""" % vars()
file.write(template)
file.close()
