Python : Automatic Apache Configuration

Yes, no need to open httpd.conf everytime. If you want to create a new website on your server, this is it. It will make changes to your httpd.conf file, make a empty folder (root document) for putting code, create database for your site in mysql, change permission and ownership of the root document and then restart the apache service. Works on python 2.x
----------------------------------------------------------------------------------------


import os
from io import open
project = raw_input(u'Enter the name of site ')
domain = raw_input (u'Enter the domain ')
docroot = raw_input(u'Enter root folder that should be created ')
virtualhost=u"""
<VirtualHost *:80>
    ServerAdmin scripto@gkmail.com
    DocumentRoot /""" +docroot+ u"""/""" +project+ u"""
    ServerName """ +project+ u""".""" +domain+ u""".com
    ErrorLog logs/""" +project+ u""".com-error_log
    CustomLog logs/""" +project+ u""".com-access_log common
</VirtualHost>"""
f = open(u'/etc/httpd/conf/httpd.conf', u'a')
f.write(virtualhost)
f.close()

cmd1 = u'mkdir /' + docroot + u'/' + project
os.system(cmd1)

cmd2 = u'mysql -u root -ppassword -e "create database ' +project+ u' "'
os.system(cmd2)

cmd3 = u'service httpd restart'
os.system(cmd3)

cmd4 = u'chmod -R 755 /' + docroot + u'/' + project
os.system(cmd4)

cmd4 = u'chown -R apache.apache /' + docroot + u'/' + project
os.system(cmd4)

print domain+ u' URL is ' +project+ u'.' +domain+ u'.com'
print u'DocumentRoot is /' +docroot+ u'/' +project
print u'Database Name is ' +project
 


Comments