0

Basic multi-wordpress with only one installation and many wp-content folders

Posted febrero 15th, 2012 in Blog, Operations and tagged by Gastón Acosta Ramas

Maybe you’re one of those looking for a easy and effective multiworpdress setup. If that’s the case, here i will explain one approach to solve this situation.

suppose we want three blogs, under wp1.com, wp2.com and wp3.com domains.
and we have a webserver with mysql, nginx and php installed.

and a directory tree like this.

database names will be the same as domain name.

now, we will use the same wordpress installation, three different wp-content folders, and three different databases.
the magic is to dinamically load the correct database, and wp-config setting based on some parameter, in our case the HTTP_POST index at $_SERVER global.

now we go to our wp-config.php and do the magic.
first dinamically detect which domain is.

// if you have www.smth.com you can get domain
// using substr function.
$domain = substr($_SERVER['HTTP_HOST'],0,3);

second setup constants according to the domain.

define(‘DB_NAME’, $domain);
define(‘DB_USER’, ‘wp_global_user’);
define(‘DB_PASSWORD’, ‘*****’);
define(‘DB_HOST’, ‘localhost’);
define(‘DB_CHARSET’, ‘utf8′);
define(‘DB_COLLATE’, ”);

//and wp-content settings
//remember: NO TRAILING SLASH

//the trick here is thath te wp-content url and plugin url must be accesible
//straight via apache
define( ‘WP_CONTENT_DIR’, “/var/www/wp/wp-content/{$domain}” );
define( ‘WP_CONTENT_URL’, “/wp-content/{$domain}” );
define( ‘WP_PLUGIN_DIR’, “/var/www/wp/wp-content/{$domain}/plugins” );
define( ‘WP_PLUGIN_URL’, “/wp-content/{$domain}/plugins” );

// if you want more control
// you can add this lines
define( ‘WP_HOME’, “http://{$domain}” );
define( ‘WP_SITEURL’, “http://{$domain}” );

 

more documentation here
http://codex.wordpress.org/Editing_wp-config.php

and that’s all folks.

Leave a Reply