WebFaction
Community site: login faq

Hi! I would like to have the option of installing spanish Wordpress instances. When I install the default Wordpress app I have to manually upload all the spanish version files via FTP, since no wplang es-ES editing on the wpconfig works.

Is there an easy way to allow this?

Thanks in advance!

asked 13 Dec '11, 03:00

ideonica
137
accept rate: 0%


Hi,

If you need to install Spanish WordPress instances on a regular basis, you could make an install script utilizing our API, and automate the procedure. You can see example install scripts here.

You can also take a look at the API tutorial.

permanent link

answered 13 Dec '11, 03:15

todork
1.2k4
accept rate: 34%

Wow, this is NICE. Anyways I miss a quick example script on the tutorials for creating the Wordpress app. I can figure out where to get the zip from, but the DB creation process for Wordpress is fairly unknown to me!

(13 Dec '11, 03:24) ideonica

Could we have a look to the standard WP installation script? It's missing from the wiki (https://wiki.webfaction.com/wiki/InstallScripts) and we'd love to have it for customizing it for downloading in other native languages!

Thanks in advance!

(11 Apr '13, 05:33) ideonica

Sure, here it is:

#!/usr/local/bin/python2.7 -S
"""
This installs WordPress 3.5.1 in the ~/webapps/<app name>/ directory.

WordPress is served by a shared Apache web server instance and PHP 5.4.

This installer creates a MySQL database named "<username>_<app name>" and configures the WordPress application for use with the database.

Note: MySQL database names are limited to 16 characters. Therefore, the WordPress application name must be less than 15 characters minus your username.

This installer creates a user "admin" with a randomly generated password. The password is stored in the "extra_info" field after the installer has finished. The password is also the password for the MySQL database.

Note: Any subsequent changes to the admin password will not be reflected in the control panel's "extra info" field.

Please see http://docs.webfaction.com/software/wordpress.html#sending-email-from-wordpress for instructions on sending mail with this application.

WordPress documentation is available at: http://docs.webfaction.com/software/wordpress

"autostart": not applicable
"extra info": leave empty; it will be set by the installer and will contain the WordPress admin password
"""

import sys
import xmlrpclib
import random
import string

def random_string(length=64):
    valid_alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    return ''.join((random.choice(valid_alphabet) for i in xrange(length)))

def create(server, session_id, account, app_name, extra_info):
    """create the app"""
    #CODE HERE
    version = '3.5.1'
    username = account['username']
    db_name = db_username = ('%s_%s_wp' % (username, app_name))[:16]
    db_password = ''.join(random.choice(string.digits + string.letters) for i in range(8))
    server.create_db(session_id, db_name, 'mysql', db_password)
    app = server.create_app(session_id, app_name, 'static_php54', 
                            False, db_password, '')
    app_dir = '%s/%s/webapps/%s/' % (account['home'], account['username'], app['name'])
    server.system(session_id, (
        'rm index.html;'
        'wget -O wordpress-%(version)s.tar.gz -q http://wordpress.org/wordpress-%(version)s.tar.gz;'
        'tar fxz wordpress-%(version)s.tar.gz;'
        'mv wordpress/* .;'
        # Cleanup
        'rm wordpress-%(version)s.tar.gz;'
        'rm -rf wordpress/;'
        ) % locals())
    wp_auth_key = random_string()
    wp_secure_auth_key = random_string()
    wp_logged_in_key = random_string()
    wp_nonce_key = random_string()
    wp_auth_salt = random_string()
    wp_secure_auth_salt = random_string()
    wp_logged_in_salt = random_string()
    wp_nonce_salt = random_string()

    cmd = """\
    cd %(app_dir)s
    cp wp-config-sample.php wp-config.php
    sed -i "s/^define('DB_PASSWORD', '.*');/define('DB_PASSWORD', '%(db_password)s');/" wp-config.php
    sed -i "s/^define('DB_NAME', '.*');/define('DB_NAME', '%(db_name)s');/" wp-config.php
    sed -i "s/^define('DB_USER', '.*');/define('DB_USER', '%(db_name)s');/" wp-config.php
    sed -i "s/.*define('AUTH_KEY.*/define('AUTH_KEY', '%(wp_auth_key)s');/" wp-config.php
    sed -i "s/.*define('SECURE_AUTH_KEY.*/define('SECURE_AUTH_KEY', '%(wp_secure_auth_key)s');/" wp-config.php
    sed -i "s/.*define('LOGGED_IN_KEY.*/define('LOGGED_IN_KEY', '%(wp_logged_in_key)s');/" wp-config.php
    sed -i "s/.*define('NONCE_KEY.*/define('NONCE_KEY', '%(wp_nonce_key)s');/" wp-config.php
    sed -i "s/.*define('AUTH_SALT.*/define('AUTH_SALT', '%(wp_auth_salt)s');/" wp-config.php
    sed -i "s/.*define('SECURE_AUTH_SALT.*/define('SECURE_AUTH_SALT', '%(wp_secure_auth_salt)s');/" wp-config.php
    sed -i "s/.*define('LOGGED_IN_SALT.*/define('LOGGED_IN_SALT', '%(wp_logged_in_salt)s');/" wp-config.php
    sed -i "s/.*define('NONCE_SALT.*/define('NONCE_SALT', '%(wp_nonce_salt)s');/" wp-config.php
    """ % locals()

    server.system(session_id, cmd)
    try:
        server.run_php_script(session_id, '%s/wp-admin/install.php' % app_dir, "<?php $_GET['step'] = '2'; $_POST['weblog_title'] = 'My blog'; $_POST['admin_email'] = 'you@example.com'; $_POST['admin_password'] = '%s'; $_POST['admin_password2'] = '%s'; ?>" % (db_password, db_password))
    except Exception as e:
        if "sendmail" in str(e):
            pass
    print app['id']

def delete(server, session_id, account, app_name, extra_info):
    """delete the app"""
    # Delete application and database.
    db_name = ('%s_%s' % (account['username'], app_name))[:16]
    server.delete_app(session_id, app_name)
    try:
        server.delete_db(session_id, db_name, 'mysql')
    except:
        pass

def main(action, username, password, machine, app_name, autostart, extra_info):
    server = xmlrpclib.Server('https://api.webfaction.com/')
    session_id, account = server.login(username, password, machine)

    # create or delete the app
    globals()[action](server, session_id, account, app_name, extra_info)

if __name__ == '__main__':
    try:
        main(*sys.argv[1:])
    except xmlrpclib.Fault, e:
        print e.faultString
(12 Apr '13, 10:48) seanf
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×244
×54
×2

question asked: 13 Dec '11, 03:00

question was seen: 5,977 times

last updated: 12 Apr '13, 10:48

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM