Yet another Wordpress hack to host virtual users

Hey! After searching and, or reading many solutions on hosting virtual user blogs on single, shared Wordpress installation, I have figured out quite a simple and smart hack.

A few of the things, I have been considering are as follows:

  1. Either use a single database with unique $table_prefix or use unique databases for each user.
  2. Users may use unique blognames and, or descriptions, but I prefer same and, or similar blognames and, or descriptions for consistent look and feel.
  3. Users are not allowed to add and, or remove plugins, themes and, or scripts; but they may use and, or activate any of the available ones.
  4. In case a user direly needs something, one may request and, or convince the sysadmin to do so.

I just needed to change the default wp-config.php file, after installing and, or extracting all the Wordpress 2.1.1 (was working fine with version 2.1 also) files in to /usr/share/wordpress directory.

Here follows a modified and default /usr/share/wordpress/wp-config.php file:

<?php
// Get virtual user's personalized wp-config.php, i.e.
// the $HOME/.wordpress/wp-config.php
$parts = explode('/',$_SERVER['SCRIPT_FILENAME']);
require '/'. $parts[1] .'/'. $parts[2]. '/.wordpress/wp-config.php';

// These lines have been taken from wp-config-sample.php
define('ABSPATH', dirname(__FILE__).'/');
require_once(ABSPATH.'wp-settings.php');
?>

In step 2, I created a few apache userdir symlinks as root for all those users whom I wanted to blog:

# ln -s /usr/share/wordpress /home/user/public_html

In step 3, I needed to create a sub-directory and user specific wp-config.php file from a slightly modified wp-config-sample.php file:

<?php
// ** MySQL settings ** //
define('DB_NAME', 'wordpress');    // The name of the database
define('DB_USER', 'username');     // Your MySQL username
define('DB_PASSWORD', 'password'); // ...and password
define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value

// You can have multiple installations in one database if you give each a unique prefix
$table_prefix  = 'wp_';   // Only numbers, letters, and underscores please!

// Change this to localize WordPress.  A corresponding MO file for the
// chosen language must be installed to wp-includes/languages.
// For example, install de.mo to wp-includes/languages and set WPLANG to 'de'
// to enable German language support.
define ('WPLANG', '');

/* That's all, stop editing! Happy blogging. */
?>

Now create a user specific sub-directory and configuration file:

# mkdir /home/user/.wordpress
# cp /usr/share/wordpress/wp-config-sample.php /home/user/.wordpress/wp-config.php

We may edit these user specific configuration files as per requirements.

In the finishing step, I needed to create user specific empty databases, which you may omitt if you want to use single database for your users.

Finally, you yourself may login as admin for your new users and edit and, or tweak a bit Wordpress options for them, except for changing their default admin password, which shall be or has been mailed to them by wordpress; this and all the above steps can auto-magically be performed with a shell script, if you want to do it for hundreds of thousand users.

Furthermore, you may tweak around a bit the /usr/share/wordpress/wp-admin/upgrade-schema.php file too, but you should know what you are doing ;)

No doubt, the Wordpress rocks!

1 Response to “Yet another Wordpress hack to host virtual users”


  1. 1 bsd

    So, might be looking for a script to do all this auto-magically for you … No problem, feel free to download wordpress-2.2.1-patch.tar.gz or wordpress-2.3.1-patch.tar.gz, contains a few patches and the addblog.sh script.

    Here is a README file for further details and, or instructions.

    Have a nice day!

Leave a Reply





Close
E-mail It