Hello world!Multiple wordpress blogs on one server
Single WordPress application has only single blog (1:1). I'd like to show building multiple blogs by adding 10 lines and 1 symbolic link(or 6 lines of .htaccess) (1:n).
This method also provide single file management. It means you just need to install theme and plugin file once whichever you want to use the theme or plugin on blogs.
You can extend your runnning wordpress blog to multiple blogs without downtime and risks.
Instructions
- Deploy wordpress files
- Install main wordpress
- Make change for sub wordpress
- Symbolic link
- or .htaccess
- Modify wp-config.php
- Install sub wordpress
1. Deploy wordpress files
Upload wordpress file and upload to your server.
2. Install main wordpress
Go to admin page and setup first blog by running the installation script.
http://codex.wordpress.org/Installing_WordPress#Step_5:_Run_the_Install_Script
Nothing is special by now.
3. Make change for sub wordpress
You need to chose either Symbolic link approach or htaccess approach. Behavior of multiple blogs are same whichever you choose.
Sometimes your choise depends on your server restriction. You will need shell account login to make symbolic links. Sometimes, .htaccess is now allowed by server administration. You might need to check your server setting.
If you don't understand symbolic link or .htaccess, you'd better use 'symbolic link'. It's common and allowed by most ISPs.
Following instruction is assuming the main wordpress is installed "/home/matsu/public_html/blog" and URL is http://matsu.tymy.net/blog/ and you're going to make a blog which will be "/home/matsu/public_html/milklog" http://matsu.tymy.net/milklog/.
3.1 Symbolic link
Just make a new symbolic link from new blog name to existing wordpress directory.
Example:
% cd /home/matsu/public_html % ln -s blog milk_log
3.2 .htaccess
Make an .htaccess and upload to the parent of your wordpress directory. In this assumption, the .htaccess will be placed /home/matsu/public_html/.htaccess
Example:
RewriteEngine on
RewriteBase /
# rewrite milk blog block
RewriteRule milklog/(.*) /blog/$1
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule milklog/(.*) /blog/index.php [L]
# /end of rewrite milk blog
If you want to build more blogs, copy and past the block section and modify corresponding to your blog path.
4. Modify wp-config.php
Add following code after "$table_prefix = 'wp_';".
// determine table prefix according to the REQUEST_URI
$prefix_array = array(
'/~matsu/milklog' => 'wp_milklog_'
);
if($prefix_array){
$uri = $_SERVER['REQUEST_URI'];
foreach($prefix_array as $search_uri => $search_table_prefix){
if(strpos($uri, $search_uri) === false){ continue; }
$table_prefix = $search_table_prefix;
}
}
5. Install sub wordpress
Go to the admin page of the new blog and run the install script.
Example:
http://matsu.tymy.net/milklog/wp-admin/install.php
Evaluation
Advantage
- Mentainance free: I put this code while wordpress 2.6 and still working on 2.9.
- Small changes: just add 10 lines and make symbolic link(or create 5 line htaccess). The page, which is on the first result on google, need to create many symbolic links and may not work future wordpress release.
Disadvantage
- Shared filesystem: filesystem is not independent to the blogs. Administrator of blogs have to care about XML sitemap files, robots.txt, uploaded files and other filesystem dependent functions.
Support files
You can see my config files from following link.
My wp-config.php.
My .htaccess.
I'm running 3 wordpress blogs.
http://matsu.tymy.net/blog/
http://matsu.tymy.net/enblog/
http://matsu.tymy.net/milklog/
