Battle of the Fronteer - Blog

(function(){

var botf = new Blog('Battle of the Fronteer');

botf.author = {

name: 'Glenn Glerum',

skills: 'xhtml, css, javascript'

interests: 'seo, accessibility, (mobile) browser compatibility, microformats'

}

botf.description = 'Blogging at and about the frontend';

})

One wordpress installation for multiple accounts

I was looking for a way to use one wordpress installation for multiple sites. I feel that it is unnecessary to unpack the core files for every wordpress installation. Wordpress self offers a way to create a network, your own webring of blogs.

So i did some searching and experimenting and I came up the following solution.

Setup Wordpress
When you do not have an existing wordpress installation on a virtual host, create one. Point your virtual host to the document root of the website, not at the wordpress directory. Like '/var/www/mywebsite/public_html'  , wordpress resides in 'public_html'. The website should be accessible from 'mywebsite.com/wordpress'.

wp-content & wp-config
The wp-content directory contains your themes and plugins, this is the directory that differs between websites. So we should move this directory from the core files to a different location, in my case I placed the directory in the website root.

So if wordpress is located in '/var/www/mywebsite/public_html/wordpress' we want to move the 'wp-content' directory to '/var/www/public_html/mywebsite'. After you have moved the 'wp-content' directory to its new location the website will show a blank page, this is because we haven't told wordpress where it can find the directory. Open the 'wp-config.php' file and add the following lines after the database rules;

/** Moving wp-content directory  */
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST']  . '/wp-content');

Your website should be back in working order. Next is moving the 'wp-config.php' file to its new location next to the 'wp-content' directory. After moving find the lines in the 'wp-load.php' file that include the 'wp-config.php' file and change them to;

if ( file_exists( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php') ) {
        /* The config file resides in ABSPATH */
        require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );

So wordpress will look for the wp-config file in the site root, if you have done these steps correctly the website should still be accessible from 'mywebsite.com/wordpress'.

Moving wordpress
Now for moving wordpress to a location from which we can use it for all our websites. If it not already exists create a directory named lib in '/opt' and move the whole wordpress directory in there. Now to fix your current broken website, create a symbolic link (ln -s /opt/lib/wordpress /var/www/mywebsite/public_html/wordpress). The website should still be working, only we want to be able to access it from 'mywebsite.com' and not from 'mywebsite.com/wordpress'. So go in the administration panel (mywebsite.com/wordpress/wp-admin) to the general settings tab and change WordPress address (URL) to 'mywebsite.com/wordpress' and Site address (URL) to 'mywebsite.com'. Your will be shown an error, to fix this "copy" 'index.php' from the 'wordpress' directory to '/var/www/mywebsite/public_html' and change the include line to;

require('./wordpress/wp-blog-header.php');

The website should now be running from 'mywebsite.com' and the administration panel from 'mywebsite.com/wordpress/wp-admin'. You can shorten the link to the panel easily by creating a symbolic link to the wp-admin directory (ln -s wordpress/wp-admin cms). The panel should be accessible through 'mywebsite.com/cms'

A new website, now what
So we just set the basis for multiple websites and changed the structure for an existing wordpress website. So how do we create a new website?. First create your virtualhost with the needed directory structure '/var/www/mynewsite/public_html'. Copy the 'wp-content' directory, 'wp-config' and 'index' file from the existing website to the new website root directory (/var/www/mynewsite/public_html). Create a symbolic link to the wordpress directory (ln -s /opt/lib/wordpress /var/www/mywebsite/public_html/wordpress). When you view your new website you will see the existing website, this is because you need to change the database settings in the 'wp-config ' file. After that wordpress will help you configure the database and you have setup your new website.

References:
http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content
http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

No comments:

Post a Comment