Automatically Installing Wordpress

Update: Automatically Installing Wordpress Forum Post

Automating the install of wordpress saves a great deal of time.  You can easily write a script to copy wordpress to a directory, append your vhosts, auto-generate a wp-config.php and restart apache, so I won’t be including that part of the code in this post.  I will cover the initial install, and also the sql injection to get wordpress up and running.

Automatically Installing Wordpress Part 1

import urllib

# make sure you set WEBLOG_TITLE and ADMIN_EMAIL
params = urllib.urlencode({'weblog_title' : WEBLOG_TITLE, 'admin_email' : ADMIN_EMAIL})

# install wordpress
f = urllib.urlopen('http://MY_DOMAIN/wp-admin/install.php?step=2', params)
data = f.read()
f.close()

At this point, you have installed wordpress, but you’ll want to set some options.  This next example shows some examples of how you can manipulate the base installation of wordpress.

Automatically Installing Wordpress Part 2

import MySQLdb

tblPrefix = 'TABLE_PREFIX'

conn = MySQLdb.connect (host='localhost', user='USERNAME', passwd='PASSWORD', db='DATABASE')
cursor = conn.cursor()

# delete hello world post
cursor.execute('delete * from %sposts' % (tblPrefix))

# create a password, wp makes a random default one
cursor.execute("""update %susers set user_pass = md5('PASSWORD') where user_login='admin'""" % (tblPrefix))

# title the blog
cursor.execute('''update %soptions set option_value='TITLE_OF_BLOG' where option_id=3''' % (tblPrefix))

# make the blog public
cursor.execute('''update %soptions set option_value = '1' where option_name = 'blog_public' ''' % (tblPrefix))

# allow pingback
cursor.execute("""update %soptions set option_value = '1' where option_name = 'default_pingback_flag'""" % (tblPrefix))

# open for pings
cursor.execute("""update %soptions set option_value = 'open' where option_name = 'default_ping_status'""" % (tblPrefix))

# open for comments
cursor.execute("""update %soptions set option_value = 'open' where option_name = 'default_comment_status'""" % (tblPrefix))

# disallow comment registration
cursor.execute("""update %soptions set option_value = '0' where option_name = 'comment_registration'""" % (tblPrefix))

# non-static page
cursor.execute("""update %soptions set option_value = '0' where option_name = 'page_on_front'""" % (tblPrefix))

cursor.close()
conn.close()

Leave a comment

You must be logged in to post a comment.