2008.11.28 - 17:49:49 PDT
Ok, I've got this up and running the way I want now, so I figure I'll document both for myself and for the greater good.
Goals:
* Run multiple mediawiki sites using a single codebase and sharing users and login sessions (log in once for all wikis)
Assumptions:
* A very basic understanding of the shell (commands like cd, mkdir, tar)
* You have at least a minimal understanding of mediawiki installation and can
get one site up and running
* Apache 2 (though these methods may work with version 1, it's untested)
* Apache runs as group apache
* A single MySQL database for the wiki running on localhost.
* Root access to your webserver
* Latest version of mediawiki (1.13.2 at the time of this writing) tarballed in
your home directory.
* Write access to /home/www (see Conventions) for your normal user account.
* You'll set up one wiki called "main" and create other wikis named whatever.
If you don't want to have a "main" wiki, just change the naming of the
first wiki to one of the wikis you would like to install.
Conventions:
* Paths will live under /home/www -- modify for your environment
* /home/www is NOT a DocumentRoot for apache (including any virtualhosts, etc)
* Commands will be inside quote tags and start with "$" for user commands and
"#" for root commands
* Commands may be split over multiple lines for simplicity with a backslash (\).
* Text to go into files will also be inside quote tags, but will not be
prefixed with $ or # (except for comments, it should be obvious which is
which).
* Variables that you should change will be all caps and are self-documenting
(e.g., YOUR_IP_ADDRESS)
* Database names, user names, etc can be altered to your liking. I'll just use
what's conventional.
References:
* See the MediaWiki Installation Guide [mediawiki.org].
First, we'll set up two instances of mediawiki. One is kept pristine, and is just for running config/index.php to create all the database tables and LocalSettings.php. This wouldn't be totally necessary, but it makes for a nice way to do create new wikis without exposing yourself to nastiness during the config stage.
Give apache write access to the wikiadmin/config directory.
If you're paranoid (like me), you can remove the config files from the wikicode directory as we won't ever use them.
Now we have two installations of the code. One in the "wikicode" directory and one in the "wikiadmin" directory. For the sake of saving space, you can pare down the wikiadmin installation if you like. Personally, I removed everything under lanuages/messages except for MessagesEn.php. You can probably trim a lot more if you want.
It is absolutely critical that neither of these directories are configured as a DocumentRoot for your site, whether virtualhost or main configuration. Personally, I use an empty directory /home/www/wiki as my DocumentRoot for the wiki VirtualHost.
Next, edit your apache config to give you (and only you) access to your wikiadmin directory. If you are using a virtualhost, this goes inside the <VirtualHost> declaration, otherwise it can live in your main configuration:
Create your wiki database, and give the wiki access to it. You can do this however you like, but I prefer the simple CLI interface. Enter your mysql root user's password when prompted.
From here, you can set up your first wiki. Personally, I created a "Main Wiki." This first wiki setup will also defined the shared database tables, though any of them really could be used.
Go to http://YOURSITE_COM/wikiadmin [YOURSITE_COM]
Follow the configuration setup as normal. Most of the settings you can choose for yourself, I'll just mention a few important ones.
Wiki name: Main Wiki
Admin username: WikiSysOp
Password: YOUR_WIKI_ADMIN_PASSWORD
Password confirm: YOUR_WIKI_ADMIN_PASSWORD
Database type: MySQL
Database host: localhost
DB username: wikiuser
DB password: YOUR_WIKI_DATABASE_USER_PASSWORD
DB password confirm: YOUR_WIKI_DATABASE_USER_PASSWORD
Database table prefix: main_
And that's it. Make sure the rest of the settings are the way you want them, then click "Install MediaWiki!"
Next, move the LocalSettings.php you just created into the wikicode root directory. Be sure to rename it to LocalSettings-main.php! Also, be sure to move the file not just copy it. We don't want a LocalSettings.php hanging out in wikiadmin/config anymore.
Now you need to create the real LocalSettings.php. In your favorite text editor, just create /home/www/wikicode/LocalSettings.php to contain the following:
You can edit the html to present something nicer if you want. It really shouldn't happen that anyone sees that, unless you screw up your config.
Now you need to edit a few things in LocalSettings-main.php. These will be the things you change for each wiki you create. If these variables don't exist, add them.
If you want to enable uploads (and keep them seperate per wiki), then you'll first need to create an uploads directory and make it writeable by apache.
Then in LocalSettings-main.php change or create the variables:
Now we're all set. Update your apache config to serve the new wiki (in VirtualHost directive or main config).
Your first wiki is now ready to go. Visit http://YOURSITE_COM/main [YOURSITE_COM] to see it in action!
Now that we have all the difficult crap out of the way, adding new wikis is pretty simple. Let's say we're setting up a new wiki called "anotherwiki."
Go to the /wikiadmin site to create a new LocalSettings.php. Visit http://YOURSITE_COM/wikiadmin [YOURSITE_COM] and go through the mediawiki configuration again. Assuming you want the same settings, the only things you'll need to enter differently than last time are the "Wiki name" and "Database table prefix" settings.
Wiki name: Another Wiki
Admin username: WikiSysOp # Same as before
Password: YOUR_WIKI_ADMIN_PASSWORD # Same as before
Password confirm: YOUR_WIKI_ADMIN_PASSWORD # Same as before
Database type: MySQL # Same as before
Database host: localhost # Same as before
DB username: wikiuser # Same as before
DB password: YOUR_WIKI_DATABASE_USER_PASSWORD # Same as before
DB password confirm: YOUR_WIKI_DATABASE_USER_PASSWORD # Same as before
Database table prefix: another_
Click the "Install MediaWiki!" button. Then move LocalSettings.php to it's new home.
Edit the new LocalSettings-anotherwiki.php to change (or add) the same variables as before.
If you enabled uploading, don't forget to make the new directory, and let apache write to it.
Then update your apache config the same way you did earlier.
Ta-da! You just installed a new wiki. You can repeat those steps any time you want to create a new one.
You can now go add a user on one of your wikis, and that user will be able to log in to any of them. You can also log in at one wiki and go visit one of the others, and you will still be logged in as the same user.
Note that this doesn't affect things like "My Contributions" and whathaveyou. Those will still remain seperate for each wiki, as they should.
One final thing you should probably do is create a robots.txt in your DocumentRoot. I have one that looks like this:
Goals:
* Run multiple mediawiki sites using a single codebase and sharing users and login sessions (log in once for all wikis)
Assumptions:
* A very basic understanding of the shell (commands like cd, mkdir, tar)
* You have at least a minimal understanding of mediawiki installation and can
get one site up and running
* Apache 2 (though these methods may work with version 1, it's untested)
* Apache runs as group apache
* A single MySQL database for the wiki running on localhost.
* Root access to your webserver
* Latest version of mediawiki (1.13.2 at the time of this writing) tarballed in
your home directory.
* Write access to /home/www (see Conventions) for your normal user account.
* You'll set up one wiki called "main" and create other wikis named whatever.
If you don't want to have a "main" wiki, just change the naming of the
first wiki to one of the wikis you would like to install.
Conventions:
* Paths will live under /home/www -- modify for your environment
* /home/www is NOT a DocumentRoot for apache (including any virtualhosts, etc)
* Commands will be inside quote tags and start with "$" for user commands and
"#" for root commands
* Commands may be split over multiple lines for simplicity with a backslash (\).
* Text to go into files will also be inside quote tags, but will not be
prefixed with $ or # (except for comments, it should be obvious which is
which).
* Variables that you should change will be all caps and are self-documenting
(e.g., YOUR_IP_ADDRESS)
* Database names, user names, etc can be altered to your liking. I'll just use
what's conventional.
References:
* See the MediaWiki Installation Guide [mediawiki.org].
First, we'll set up two instances of mediawiki. One is kept pristine, and is just for running config/index.php to create all the database tables and LocalSettings.php. This wouldn't be totally necessary, but it makes for a nice way to do create new wikis without exposing yourself to nastiness during the config stage.
$ cd /home/www/ && tar xzf ~/mediawiki-1.13.2.tar.gz
$ cp -pr mediawiki-1.13.2 wikicode
$ mv mediawiki-1.13.2 wikiadmin
$ cp -pr mediawiki-1.13.2 wikicode
$ mv mediawiki-1.13.2 wikiadmin
Give apache write access to the wikiadmin/config directory.
# chown :apache wikiadmin/config
# chmod 0770 wikiadmin/config
# chmod 0770 wikiadmin/config
If you're paranoid (like me), you can remove the config files from the wikicode directory as we won't ever use them.
$ rm -rf wikicode/config
Now we have two installations of the code. One in the "wikicode" directory and one in the "wikiadmin" directory. For the sake of saving space, you can pare down the wikiadmin installation if you like. Personally, I removed everything under lanuages/messages except for MessagesEn.php. You can probably trim a lot more if you want.
It is absolutely critical that neither of these directories are configured as a DocumentRoot for your site, whether virtualhost or main configuration. Personally, I use an empty directory /home/www/wiki as my DocumentRoot for the wiki VirtualHost.
Next, edit your apache config to give you (and only you) access to your wikiadmin directory. If you are using a virtualhost, this goes inside the <VirtualHost> declaration, otherwise it can live in your main configuration:
Alias /wikiadmin /home/www/wikiadmin
<Directory /home/www/wikiadmin>
Order deny,allow
Deny from all
Allow from YOUR_IP_ADDRESS
</Directory>
<Directory /home/www/wikiadmin>
Order deny,allow
Deny from all
Allow from YOUR_IP_ADDRESS
</Directory>
Create your wiki database, and give the wiki access to it. You can do this however you like, but I prefer the simple CLI interface. Enter your mysql root user's password when prompted.
$ mysql -u root -p -e 'create database wikidb'
$ mysql -u root -p -e "grant create, select, insert, update, delete, alter, \
lock tables on wikidb.* to wikiuser@localhost identified by \
'YOUR_WIKI_DATABASE_USER_PASSWORD'"
$ mysql -u root -p -e "grant create, select, insert, update, delete, alter, \
lock tables on wikidb.* to wikiuser@localhost identified by \
'YOUR_WIKI_DATABASE_USER_PASSWORD'"
From here, you can set up your first wiki. Personally, I created a "Main Wiki." This first wiki setup will also defined the shared database tables, though any of them really could be used.
Go to http://YOURSITE_COM/wikiadmin [YOURSITE_COM]
Follow the configuration setup as normal. Most of the settings you can choose for yourself, I'll just mention a few important ones.
Wiki name: Main Wiki
Admin username: WikiSysOp
Password: YOUR_WIKI_ADMIN_PASSWORD
Password confirm: YOUR_WIKI_ADMIN_PASSWORD
Database type: MySQL
Database host: localhost
DB username: wikiuser
DB password: YOUR_WIKI_DATABASE_USER_PASSWORD
DB password confirm: YOUR_WIKI_DATABASE_USER_PASSWORD
Database table prefix: main_
And that's it. Make sure the rest of the settings are the way you want them, then click "Install MediaWiki!"
Next, move the LocalSettings.php you just created into the wikicode root directory. Be sure to rename it to LocalSettings-main.php! Also, be sure to move the file not just copy it. We don't want a LocalSettings.php hanging out in wikiadmin/config anymore.
$ mv /home/www/wikiadmin/config/LocalSettings.php \
/home/www/wikicode/LocalSettings-main.php
/home/www/wikicode/LocalSettings-main.php
Now you need to create the real LocalSettings.php. In your favorite text editor, just create /home/www/wikicode/LocalSettings.php to contain the following:
<?php
list($null, $toplevel, $dontcare) = explode('/', strtolower($_SERVER['REQUEST_URI']));
if (is_file("LocalSettings-$toplevel.php")) {
require_once("LocalSettings-$toplevel.php");
}
else {
print <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-flat.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>wiki not found</title>
</head>
<body>
<p>The wiki you were looking for was not found.</p>
</body>
EOF;
}
?>
list($null, $toplevel, $dontcare) = explode('/', strtolower($_SERVER['REQUEST_URI']));
if (is_file("LocalSettings-$toplevel.php")) {
require_once("LocalSettings-$toplevel.php");
}
else {
print <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-flat.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>wiki not found</title>
</head>
<body>
<p>The wiki you were looking for was not found.</p>
</body>
EOF;
}
?>
You can edit the html to present something nicer if you want. It really shouldn't happen that anyone sees that, unless you screw up your config.
Now you need to edit a few things in LocalSettings-main.php. These will be the things you change for each wiki you create. If these variables don't exist, add them.
$wgScriptPath = "/main";
$wgScript = "/main/index.php";
$wgSharedDB = "wikidb";
$wgSharedPrefix = "main_";
$wgSharedTables = array( 'user', 'user_groups', 'interwiki', 'ipblocks' );
$wgArticlePath = "/main/$1"; # This isn't necessary, but will give you nice short URLs. Do it!
$wgUsePathInfo = true;
$wgScript = "/main/index.php";
$wgSharedDB = "wikidb";
$wgSharedPrefix = "main_";
$wgSharedTables = array( 'user', 'user_groups', 'interwiki', 'ipblocks' );
$wgArticlePath = "/main/$1"; # This isn't necessary, but will give you nice short URLs. Do it!
$wgUsePathInfo = true;
If you want to enable uploads (and keep them seperate per wiki), then you'll first need to create an uploads directory and make it writeable by apache.
$ mkdir -p /home/www/uploads/main
# chown :apache /home/www/uploads/main
# chmod 0775 /home/www/uploads/main
# chown :apache /home/www/uploads/main
# chmod 0775 /home/www/uploads/main
Then in LocalSettings-main.php change or create the variables:
$wgEnableUploads = true;
$wgUploadsDirectory = "/home/www/uploads/main";
$wgUploadsDirectory = "/home/www/uploads/main";
Now we're all set. Update your apache config to serve the new wiki (in VirtualHost directive or main config).
Alias /main/skins /home/www/wikicode/skins
Alias /main/images /home/www/uploads/images # If you enabled uploads
Alias /main/index.php /home/www/wikicode/index.php
Alias /main /home/www/wikicode/index.php
Alias /main/images /home/www/uploads/images # If you enabled uploads
Alias /main/index.php /home/www/wikicode/index.php
Alias /main /home/www/wikicode/index.php
Your first wiki is now ready to go. Visit http://YOURSITE_COM/main [YOURSITE_COM] to see it in action!
Now that we have all the difficult crap out of the way, adding new wikis is pretty simple. Let's say we're setting up a new wiki called "anotherwiki."
Go to the /wikiadmin site to create a new LocalSettings.php. Visit http://YOURSITE_COM/wikiadmin [YOURSITE_COM] and go through the mediawiki configuration again. Assuming you want the same settings, the only things you'll need to enter differently than last time are the "Wiki name" and "Database table prefix" settings.
Wiki name: Another Wiki
Admin username: WikiSysOp # Same as before
Password: YOUR_WIKI_ADMIN_PASSWORD # Same as before
Password confirm: YOUR_WIKI_ADMIN_PASSWORD # Same as before
Database type: MySQL # Same as before
Database host: localhost # Same as before
DB username: wikiuser # Same as before
DB password: YOUR_WIKI_DATABASE_USER_PASSWORD # Same as before
DB password confirm: YOUR_WIKI_DATABASE_USER_PASSWORD # Same as before
Database table prefix: another_
Click the "Install MediaWiki!" button. Then move LocalSettings.php to it's new home.
$ mv /home/www/wikiadmin/config/LocalSettings.php \
/home/www/wikicode/LocalSettings-anotherwiki.php
/home/www/wikicode/LocalSettings-anotherwiki.php
Edit the new LocalSettings-anotherwiki.php to change (or add) the same variables as before.
$wgScriptPath = "/anotherwiki";
$wgScript = "/anotherwiki/index.php";
$wgSharedDB = "wikidb";
$wgSharedPrefix = "another_";
$wgSharedTables = array( 'user', 'user_groups', 'interwiki', 'ipblocks' );
$wgArticlePath = "/anotherwiki/$1";
$wgUsePathInfo = true;
$wgEnableUploads = true; # If you want to enable uploads
$wgScript = "/anotherwiki/index.php";
$wgSharedDB = "wikidb";
$wgSharedPrefix = "another_";
$wgSharedTables = array( 'user', 'user_groups', 'interwiki', 'ipblocks' );
$wgArticlePath = "/anotherwiki/$1";
$wgUsePathInfo = true;
$wgEnableUploads = true; # If you want to enable uploads
If you enabled uploading, don't forget to make the new directory, and let apache write to it.
$ mkdir /home/www/uploads/anotherwiki
# chown :apache /home/www/uploads/anotherwiki
# chmod 0775 /home/www/uploads/anotherwiki
# chown :apache /home/www/uploads/anotherwiki
# chmod 0775 /home/www/uploads/anotherwiki
Then update your apache config the same way you did earlier.
Alias /anotherwiki/skins /home/www/wikicode/skins
Alias /anotherwiki/images /home/www/uploads/images # If you enabled uploads
Alias /anotherwiki/index.php /home/www/wikicode/index.php
Alias /anotherwiki /home/www/wikicode/index.php
Alias /anotherwiki/images /home/www/uploads/images # If you enabled uploads
Alias /anotherwiki/index.php /home/www/wikicode/index.php
Alias /anotherwiki /home/www/wikicode/index.php
Ta-da! You just installed a new wiki. You can repeat those steps any time you want to create a new one.
You can now go add a user on one of your wikis, and that user will be able to log in to any of them. You can also log in at one wiki and go visit one of the others, and you will still be logged in as the same user.
Note that this doesn't affect things like "My Contributions" and whathaveyou. Those will still remain seperate for each wiki, as they should.
One final thing you should probably do is create a robots.txt in your DocumentRoot. I have one that looks like this:
User-Agent: *
Disallow: /*/Special:Search
Disallow: /*/Special:Random
Disallow: /*/Special:Search
Disallow: /*/Special:Random


