I wanted to create multiple word press installations in the same database but they needed to have a common user database. After much searching and experimentation, I found some posts on the word press support forum dealing with this sort of installation.
I finally managed to get that done and working. The procedure is listed below -
1. Create a database with your web host using my-sql. Lets say the database name is “wp-xyz” and user is ‘abc” with password-”qwerty”.
2. Place the Word Press directory in the required place in your website.
3. Now edit the wp-config.php file in your wordpress main directory –// ** MySQL settings ** //
define(’DB_NAME’, ‘wp-xyz’); // The name of the database
define(’DB_USER’, ‘abc’); // Your MySQL username
define(’DB_PASSWORD’, ‘qwerty’); // …and password
define(’DB_HOST’, ‘localhost’); // 99% chance you won’t need to change this value
// if that dosen’t work write your My-SQL hostname here// You can have multiple installations in one database if you give each a unique prefix
$table_prefix = ‘wp_’; // Only numbers, letters, and underscores please!//e.g for first install you can have this value “wp_” for second you can have this “wp1_” or youca assign some meaningful /name like “myblog-”
4.Now install the database by opening your web browser and enterng the following–
http:////wp-admin/install
now follow the instructions that appear
5. Now repeat steps 1-4 with everything same except placing the Word Press files in a different directory and changing the name of the
$table_prefix
6. Now edit the /wp-config.php file and add the following –
define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
In the above wp_users and wp_usermeta can be changed to whatever act as the primary tables for your blogs. If you only want to combine the users table but retain different role and capability settings under each blog, leave out the CUSTOM_USER_META_TABLE constant
7. Now edit the /wp-includes/capabilities.php file.
In the “wp_user” class edit the following line:
$this->cap_key = $table_prefix . 'capabilities';
Modifying that line so it reflects the table prefix of the *primary* users/usermeta table, for example:
$this->cap_key = 'wp_capabilities';
where the ‘wp_’ in 'wp_capabilities' means your main blog table prefix 1.e. your wp-install number 1 table prefix
8. This process is now scalable repeat above procedure for further installs.
9. I havent taken the pains to have separate user permission for users to different Word Press installs however this is possible by
fiddling with the wp-settings.php file in the following section
// Table names
$wpdb->posts = $table_prefix . 'posts';
$wpdb->users = $table_prefix . 'users';
$wpdb->categories = $table_prefix . 'categories';
$wpdb->post2cat = $table_prefix . 'post2cat';
$wpdb->comments = $table_prefix . 'comments';
$wpdb->links = $table_prefix . 'links';
$wpdb->linkcategories = $table_prefix . 'linkcategories';
$wpdb->options = $table_prefix . 'options';
$wpdb->postmeta = $table_prefix . 'postmeta';
Special thanks to Kafkaesqui @ wordpress.org most of the work was done by him as Moderator of support forums at word Press . The orginal posts can be viewed here–
This is brilliant. It has allowed me to have a page where users submit reviews of plays (actually Wordpress Posts cunningly cloaked as reviews), and also have a current news section on the homepage where users can comment. It was important to have a difference between ‘reviews’ and ‘posts’, and not just a categorical difference, and this has provided the means. So thank you, thank you, thank you
This is a lifesaver hack. However, one thing is not clear to me. If I wanted to not declare the CUSTOM_USER_META_TABLE, what prefix would I use for the capabilities tables? Would I use the one from CUSTOM_USER_TABLE or what?
I rather answered my own question by implementing it. However, it seems there is a little bit of a flaw with not using a custom META table.
If a user registers on one blog, when they visit the other blog they have no role on that blog. Any way to overcome that for subscribers?
The CUSTOM_USER_META_TABLE constant holds User level and capabilities (i.e. in the usermeta table)
I am still trying to figure out what the CUSTOM_USER_TABLE holds
Found it !!
The user_table only stores basic info like user name, password(encrypted), nickname, email, date of join etc.
The user_meta_table has additional info like capability level(e.g subscriber/ author etc), various chat clients like yahoo etc ids, description and user level
So if you need to do any editing with user capabilities you will need to use the user_meta_tables
I was wondering if you know of anyone who has attempted this for their users from a WPMU install to a wordpress install on the same domain?
Forsee any problems?
Some people have tried basic WPMU setup but I havent seen any multiple WPMU’s. You could try the forums at Wordpress.org.
It should be possible though and the procedure should be similar to the one described above.
If you find anything do let me know.
the way you explain this procedure is terrible
It seems to work for the others and you are looking at a blog where it is implemented. so I suggest you first learn to put in some effort understanding whats written
This is kinda what I was looking for, but have a question. I used fantastico to install both of my wordpress blogs. One is on the main directory, and one is under the directory: /reviews. Would this all work the same? It appears to me that these directions may be for those who have to manually install wordpress and it’s database? Thanks ahead of time!
Thanks so much for this tip. I was trying a driffernt solution that wasnt working. Then i tried this one that didnt work either. After i threw things around my living room i decided to combine the two solutions and it worked. In order to get this to work for me on version 2.3.3 i had to do one more step.
in wp-settings.php, change…
// Table names
$wpdb->posts = $wpdb->prefix . ‘posts’;
$wpdb->users = $wpdb->prefix . ‘users’;
$wpdb->categories = $wpdb->prefix . ‘categories’;
$wpdb->post2cat = $wpdb->prefix . ‘post2cat’;
$wpdb->comments = $wpdb->prefix . ‘comments’;
$wpdb->link2cat = $wpdb->prefix . ‘link2cat’;
$wpdb->links = $wpdb->prefix . ‘links’;
$wpdb->options = $wpdb->prefix . ‘options’;
$wpdb->postmeta = $wpdb->prefix . ‘postmeta’;
$wpdb->usermeta = $wpdb->prefix . ‘usermeta’;
$wpdb->terms = $wpdb->prefix . ‘terms’;
$wpdb->term_taxonomy = $wpdb->prefix . ‘term_taxonomy’;
$wpdb->term_relationships = $wpdb->prefix . ‘term_relationships’;
to
// Table names
$wpdb->posts = $wpdb->prefix . ‘posts’;
$wpdb->users = ‘wp_users’;
$wpdb->categories = $wpdb->prefix . ‘categories’;
$wpdb->post2cat = $wpdb->prefix . ‘post2cat’;
$wpdb->comments = $wpdb->prefix . ‘comments’;
$wpdb->link2cat = $wpdb->prefix . ‘link2cat’;
$wpdb->links = $wpdb->prefix . ‘links’;
$wpdb->options = $wpdb->prefix . ‘options’;
$wpdb->postmeta = $wpdb->prefix . ‘postmeta’;
$wpdb->usermeta = ‘wp_usermeta’;
$wpdb->terms = $wpdb->prefix . ‘terms’;
$wpdb->term_taxonomy = $wpdb->prefix . ‘term_taxonomy’;
$wpdb->term_relationships = $wpdb->prefix . ‘term_relationships’;
Harsh,
I won’t be a dick in saying so like G above, but I do think he has a point. I’ve been through a lot of trial and error as I try to figure out which table prefix you’re referencing in each step. I would greatly appreciate some clarification, especially on step 7. You’ve got some great stuff here, but I feel it could be a bit clearer.
How do I get this to work for 2.5? The settings seem to be different… or am I just missing something?
havent tried WP 2.5 yet. Will post as soon as I try it. A workaround if you are installing WP on a new site would be to install 2.2 and then upgrade to 2.5..I hope thats possible. havent tried it yet.
well i can’t get it to work on 2.5 after it was working beautifully on 2.3. code has been changed…
ok, i must have messed up some code along the way…i re-edited the files and it’s working fine in 2.5
hi! is it valid to keep sessions between several wordpress?? This is… If I log in one wordpress and try to access to other wordpress, the access is granted because I´ve previously logged in the first.
I think is not possible because is necessary to modify cookies and it never will be work because them are in different paths…
I am not really sure..but someone on the wordpress forums had figured out how to create / modify cookies to allow single login between different Wp blogs. i.e you could login to one blog and there would be a cookie created. Then when you clicked on another WP blog which shared the same user table you wouldn’t need to login.