tips:farm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:farm [2012-04-21 15:29] – [Wiki Farms with DokuWiki] [[lazy farm]] says it's broken joachim aus münchen | tips:farm [2014-02-27 02:34] (current) – [Available Methods] Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Wiki Farms with DokuWiki ====== | ====== Wiki Farms with DokuWiki ====== | ||
- | This page describes a special setup of [[doku> | + | This page gives an overview over different ways to set up a **wiki farm**. In a farm, one single copy of wiki engine (the parent wiki or farm controller or **farmer**) is used to run several |
- | Alternative approaches are the [[Symlink Farm]], the [[lazy farm]] (currently broken) and [[plugin: | + | The biggest advantage is that only one instance of the wiki engine has to be maintained and upgraded. The wiki animals have completely separated contents |
- | + | ||
- | **Plugins and Templates** are common | + | |
===== Farm Directory Structure ===== | ===== Farm Directory Structure ===== | ||
Line 11: | Line 9: | ||
The farm directory can theoretically be anywhere in the file system but we recommend the following structure: | The farm directory can theoretically be anywhere in the file system but we recommend the following structure: | ||
- | * ''/ | + | * ''/ |
* ''/ | * ''/ | ||
- | * ''/ | + | * ''/ |
- | * ''/ | + | * ''/ |
- | + | ||
- | ===== Install the farmer ===== | + | |
- | + | ||
- | The farmer is the DokuWiki instance which is used to //run// all the animals. | + | |
- | + | ||
- | * **[[: | + | |
- | * **Disable the plugin manager** of the main DokuWiki instance (so it doesn' | + | |
- | ===== Add preload.php ===== | + | |
- | + | ||
- | Copy the following into ''/ | + | |
- | + | ||
- | <code php preload.php> | + | |
- | <?php | + | |
- | /** | + | |
- | * This overwrites the DOKU_CONF. Each animal gets its own configuration and data directory. | + | |
- | * | + | |
- | * The farm ($farm) can be any directory and needs to be set. | + | |
- | * Animals are direct subdirectories of the farm directory. | + | |
- | * There are two different approaches: | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | * | + | |
- | * @author Anika Henke < | + | |
- | * @author Michael Klier < | + | |
- | * @author Christopher Smith < | + | |
- | * @author virtual host part of conf_path() based on conf_path() from Drupal.org' | + | |
- | | + | |
- | * @license GPL 2 (http:// | + | |
- | */ | + | |
- | + | ||
- | $farm = '/ | + | |
- | + | ||
- | if(!defined(' | + | |
- | if(!defined(' | + | |
- | + | ||
- | + | ||
- | /** | + | |
- | * Find the appropriate configuration directory. | + | |
- | * | + | |
- | * If the .htaccess based setup is used, the configuration directory can be | + | |
- | * any subdirectory of the farm directory. | + | |
- | * | + | |
- | * Otherwise try finding a matching configuration directory by stripping the | + | |
- | * website' | + | |
- | * first configuration file found will be used; the remaining will ignored. | + | |
- | * If no configuration file is found, return the default confdir ' | + | |
- | */ | + | |
- | function conf_path($farm) { | + | |
- | + | ||
- | // htaccess based | + | |
- | if(isset($_REQUEST[' | + | |
- | if(!is_dir($farm.'/' | + | |
- | if(!defined(' | + | |
- | return $farm.'/' | + | |
- | } | + | |
- | + | ||
- | // virtual host based | + | |
- | $uri = explode('/', | + | |
- | $server = explode(' | + | |
- | for ($i = count($uri) | + | |
- | for ($j = count($server); | + | |
- | $dir = implode(' | + | |
- | if(is_dir(" | + | |
- | if(!defined(' | + | |
- | return " | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | // default conf directory in farm | + | |
- | if(is_dir(" | + | |
- | if(!defined(' | + | |
- | return " | + | |
- | } | + | |
- | // farmer | + | |
- | return DOKU_INC.' | + | |
- | } | + | |
- | + | ||
- | + | ||
- | /* Use default config files and local animal config files */ | + | |
- | $config_cascade = array( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | DOKU_INC.' | + | |
- | DOKU_CONF.' | + | |
- | ), | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ); | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | The file will overwrite DokuWiki constants (path to the configuration settings, etc.) before DokuWiki' | + | |
- | + | ||
- | This also sets a constant ('' | + | |
- | + | ||
- | This is just a minimal farm setup. You could use other resources to pull the farm directories from, like databases etc. You could automate the whole farm creation process with registering a farm etc. to your liking. Get creative, and if possible, share your ideas on this page. | + | |
- | + | ||
- | + | ||
- | ===== Two different setups ===== | + | |
- | + | ||
- | Now you have the choice between two possible farm setups: | + | |
- | + | ||
- | **Virtual Host Based Setup**: | + | |
- | * needs some kind of access to the server to create [[wp> | + | |
- | * allows any kind of domain, from '' | + | |
- | * can use the [[config: | + | |
- | + | ||
- | **Directory (.htaccess) Based Setup**: | + | |
- | * your server needs the ability to use [[wp> | + | |
- | * allows only URLs in the form of '' | + | |
- | * can use the [[config: | + | |
- | + | ||
- | ==== Virtual Host Based Setup ==== | + | |
- | + | ||
- | For this setup you have to configure the [[wp> | + | |
- | + | ||
- | <code apache> | + | |
- | NameVirtualHost * | + | |
- | + | ||
- | < | + | |
- | ServerName example.org | + | |
- | ServerAlias *.example.org | + | |
- | DocumentRoot / | + | |
- | </ | + | |
- | + | ||
- | < | + | |
- | ServerName subdomain.example.org | + | |
- | DocumentRoot / | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | On most shared hosts environments you only need to add the **server name** (your desired domain with or without subdomain) and the **document root** (always pointing to the farmer directory) through their GUI. | + | |
- | + | ||
- | ==== Directory (.htaccess) Based Setup ==== | + | |
- | + | ||
- | In this scenario we just use a single domain and access the animals via directories, | + | |
- | + | ||
- | This '' | + | |
- | Remember to enable .htaccess in the Apache Configuration (AllowOverride All) | + | |
- | + | ||
- | <code apache .htaccess> | + | |
- | RewriteEngine On | + | |
- | RewriteRule ^/? | + | |
- | RewriteRule ^/? | + | |
- | Options +FollowSymLinks | + | |
- | </ | + | |
- | + | ||
- | Be careful if you have a **redirection loop**, your DocumentRoot needs to be ''/ | + | |
- | === Comments === | + | |
- | + | ||
- | < | + | |
- | + | ||
- | < | + | |
- | + | ||
- | < | + | |
- | | + | |
- | the preload.php file send me "This wiki doesn' | + | |
- | http:// | + | |
- | I have a redirection loop.\\ | + | |
- | In order to fix it, I had to modify my .htaccess (which I wrote in my Apache' | + | |
- | <code apache> | + | |
- | RewriteEngine On | + | |
- | RewriteRule index - [L] | + | |
- | RewriteRule ^([^/]+)/(.*) ./ | + | |
- | RewriteRule ^([^/]+)$ http:// | + | |
- | </ | + | |
- | Thanks to this hack, when I type an URL without the last slash, it is rewrited with this last slash and I don't have this redirection loop anymore. | + | |
- | + | ||
- | === URL redirection with Abyss Webserver === | + | |
- | + | ||
- | As the Abysss Webserver does not feature .htaccess the URL redirection has to be configured within the server itself. The farmer is located in the subdirectory " | + | |
- | The following configuration worked for me (only one redirecting rule was necessary): | + | |
- | + | ||
- | Virtual Path Regular Expression: | + | |
- | Case Sensitive: On (default)\\ | + | |
- | No conditions\\ | + | |
- | Apply to subrequests too: On (default)\\ | + | |
- | If this rule matches: '' | + | |
- | Redirect to: ''/ | + | |
- | Append Query String: On (default)\\ | + | |
- | Escape Redirection Location: On (default) | + | |
- | + | ||
- | + | ||
- | ===== Creating an Animal ==== | + | |
- | + | ||
- | You can | + | |
- | * go through the following steps | + | |
- | * or [[# | + | |
- | * or create one master template directory which you can just copy to each new animal directory. | + | |
- | + | ||
- | ==== Step by Step === | + | |
- | + | ||
- | === Create a Directory == | + | |
- | + | ||
- | The rules how to name the directory in which your animal stores all its files depends on the setup: | + | |
- | + | ||
- | * The **virtual host setup** needs animal directory names which reflect the virtual host: e.g. '' | + | |
- | * The **directory / htaccess setup** needs the animal directory names as they are called by the URL: e.g. '' | + | |
- | + | ||
- | You can use the following shell commands to create the ''/ | + | |
- | + | ||
- | <code bash> | + | |
- | cd / | + | |
- | mkdir -p domain.org/{data/ | + | |
- | cd domain.org | + | |
- | find ./ -type d -exec chmod -v 777 {} \; | + | |
- | touch conf/ | + | |
- | chmod 666 conf/ | + | |
- | </ | + | |
- | + | ||
- | **Note:** If you have root access on the server you could also change the owner of the respective directories and configuration files to the user/group under which your webserver is running and use more restrictive (secure) | + | |
- | + | ||
- | <code bash> | + | |
- | find ./ -exec chown www-data: | + | |
- | find ./ -type d -exec chmod 775 {} \; | + | |
- | chown -R www-data: | + | |
- | chmod 664 conf/ | + | |
- | </ | + | |
- | + | ||
- | === Add Basic Configuration === | + | |
- | + | ||
- | This adds a basic configuration (with [[config: | + | |
- | + | ||
- | <code bash> | + | |
- | cat > conf/ | + | |
- | <?php | + | |
- | $conf[' | + | |
- | $conf[' | + | |
- | $conf[' | + | |
- | $conf[' | + | |
- | ?> | + | |
- | EOF | + | |
- | </ | + | |
- | + | ||
- | === Add Fixed Configuration === | + | |
- | + | ||
- | This adds some configuration to the '' | + | |
- | + | ||
- | <code bash> | + | |
- | cat > conf/ | + | |
- | <?php | + | |
- | $conf[' | + | |
- | $conf[' | + | |
- | ?> | + | |
- | EOF | + | |
- | </ | + | |
- | + | ||
- | === Set Basic Permissions === | + | |
- | + | ||
- | This sets some basic permissions to "all can read, members of the '' | + | |
- | + | ||
- | <code bash> | + | |
- | cat > conf/ | + | |
- | # <?php exit()?> | + | |
- | * @admin 255 | + | |
- | * @ALL 1 | + | |
- | EOF | + | |
- | </ | + | |
- | + | ||
- | === Add Admin User === | + | |
- | + | ||
- | The following adds a user ' | + | |
- | + | ||
- | <code bash> | + | |
- | cat > conf/ | + | |
- | # <?php exit()?> | + | |
- | admin: | + | |
- | EOF | + | |
- | </ | + | |
- | + | ||
- | ==== Using a Script to Setup an Animal ==== | + | |
- | + | ||
- | Here's a little bash script which will perform the above steps in one go inside the directory it's executed in (if you're using this with other scripts you have to make sure you '' | + | |
- | + | ||
- | <code bash addanimal.sh> | + | |
- | # | + | |
- | # This script is under public domain do with it whatever you want (yes, that includes eating it). | + | |
- | if [ $# -lt 1 ]; then | + | |
- | echo " | + | |
- | exit 1 | + | |
- | fi | + | |
- | + | ||
- | ANIMAL=${PWD}/ | + | |
- | ANIMAL_TITLE=$1 | + | |
- | + | ||
- | if [ -d $ANIMAL ]; then | + | |
- | echo " | + | |
- | exit 1 | + | |
- | fi | + | |
- | + | ||
- | echo ">> | + | |
- | + | ||
- | echo ">> | + | |
- | mkdir -p ${ANIMAL}/ | + | |
- | find ${ANIMAL}/ -type d -exec chmod 777 {} \; | + | |
- | touch ${ANIMAL}/ | + | |
- | chmod 666 ${ANIMAL}/ | + | |
- | + | ||
- | echo ">> | + | |
- | echo "<? | + | |
- | \$conf[' | + | |
- | \$conf[' | + | |
- | \$conf[' | + | |
- | \$conf[' | + | |
- | + | ||
- | echo ">> | + | |
- | echo "<? | + | |
- | \$conf[' | + | |
- | \$conf[' | + | |
- | + | ||
- | echo ">> | + | |
- | echo "# <?php exit()?> | + | |
- | * @admin 255 | + | |
- | * @ALL 1" > ${ANIMAL}/ | + | |
- | + | ||
- | echo ">> | + | |
- | echo '# <?php exit()?> | + | |
- | admin: | + | |
- | + | ||
- | echo ">> | + | |
- | echo ">> | + | |
- | echo ">> | + | |
- | + | ||
- | exit 0 | + | |
- | + | ||
- | # vim: | + | |
- | </ | + | |
- | + | ||
- | **Usage Example: | + | |
- | + | ||
- | <code bash> | + | |
- | $> cd / | + | |
- | $> addanimal cat.domain.org | + | |
- | </ | + | |
- | + | ||
- | <code bash> | + | |
- | $> cd / | + | |
- | $> addanimal subdir | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== URL Rewriting ===== | + | |
- | + | ||
- | You can use **[[: | + | |
- | + | ||
- | The [[Symlink Farm]] supports URL rewriting, too. | + | |
- | + | ||
- | ===== Enabling/ | + | |
- | + | ||
- | Since Angua the plugins can be enabled and disabled per animal using the plugin manager ([[devel: | + | |
- | But before Angua you would need to change the following: | + | |
- | + | ||
- | As described in [[devel: | + | |
- | + | ||
- | <code php> | + | |
- | require_once DOKU_INC.' | + | |
- | class Farm_Plugin_Controller extends Doku_Plugin_Controller { | + | |
- | function Farm_Plugin_Controller() { | + | |
- | parent:: | + | |
- | if (!isset($conf[' | + | |
- | $conf[' | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | function isdisabled($plugin) { | + | |
- | global $conf; | + | |
- | if (parent:: | + | |
- | return true; | + | |
- | } elseif (isset($conf[' | + | |
- | return $conf[' | + | |
- | } else { | + | |
- | return false; | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | $plugin_controller_class = ' | + | |
- | </ | + | |
- | + | ||
- | This farm plugin controller class first asks if a plugin is globally disabled and if not it looks for a configuration setting named '' | + | |
- | <code php> | + | |
- | $conf[' | + | |
- | </ | + | |
- | + | ||
- | FIXME This code should be further improved to hide disabled plugins in the configuration manager. | + | |
- | + | ||
- | ===== Discussion ===== | + | |
- | + | ||
- | ==== Patch for using preload.php in an older release ==== | + | |
- | + | ||
- | If you want to get this with releases before rc2009-02-06, | + | |
- | --- init.php | + | |
- | +++ init.php.patched | + | |
- | @@ -9,6 +9,9 @@ | + | |
- | | + | |
- | } | + | |
- | | + | |
- | + | + | |
- | + // if available load a preload config file | + | |
- | + @include(fullpath(dirname(__FILE__)).'/ | + | |
- | + | ||
- | // define the include path | + | |
- | | + | |
- | </ | + | |
- | + | ||
- | Or you could use PHP's '' | + | |
- | + | ||
- | ==== Patch/Code for making DokuWiki commandline programs work (somehow) with DokuWiki farm ==== | + | |
- | + | ||
- | Since I set " | + | |
- | + | ||
- | <code php> | + | |
- | --- indexer.php.dist | + | |
- | +++ indexer.php 2008-09-23 16: | + | |
- | @@ -2,6 +2,24 @@ | + | |
- | <? | + | |
- | if (' | + | |
- | + | ||
- | +for($i = 1; $i < sizeof($argv); | + | |
- | +{ | + | |
- | + if ($argv[$i] == " | + | |
- | + if (!isset($argv[$i+1])) { | + | |
- | + | + | |
- | + } else { | + | |
- | + | + | |
- | + | + | |
- | + | + | |
- | + if (($path= realpath($path."/ | + | |
- | + | + | |
- | + } | + | |
- | + | + | |
- | + | + | |
- | + } | + | |
- | + } | + | |
- | +} | + | |
- | + | + | |
- | | + | |
- | | + | |
- | | + | |
- | </ | + | |
- | To create an index for every farm animal, you just have to iterate over all farm animals and call the indexer script for each one.\\ | + | |
- | --- // | + | |
- | + | ||
- | + | ||
- | Another approach is using an environment variable for setting the animal and checking for that environment variable in inc/ | + | |
- | + | ||
- | <code php> | + | |
- | // cli | + | |
- | if (' | + | |
- | if (!is_dir($farm.'/' | + | |
- | if (!defined(' | + | |
- | return $farm.'/' | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | With that you can use all cli scripts by executing | + | |
- | <code bash> | + | |
- | animal=YOUR_ANIMAL ./ | + | |
- | </ | + | |
- | --- [[user> | + | |
- | ==== Variant of the directory based setup (farmer and animal at same directory level) ==== | + | |
- | + | ||
- | If you want to have both DokuWiki farmer and animals each located in an own subdirectory of the server you have to use a different preload.php. basically you have to set additional constants in order to have anything working. of course you still have to set URL rewriting in your webserver (see above). | + | |
- | + | ||
- | < | + | |
- | <?php | + | |
- | /** | + | |
- | * This overwrites the DOKU_CONF. Each farm gets its own configuration and data directory. | + | |
- | * Animal is not a subdirectory with the farmer, but at same level directory level. | + | |
- | * Access farmer like this: http:// | + | |
- | * Access animal like this: http:// | + | |
- | * Farmer on server e.g. / | + | |
- | * Animal on server e.g. / | + | |
- | */ | + | |
- | + | ||
- | // the home directory for all animals and the farmer located in subdirectories | + | |
- | $farmdir = DOKU_INC.' | + | |
- | + | ||
- | // don't do anything if the animal doesn' | + | |
- | if(isset($_REQUEST[' | + | |
- | if(!is_dir($farmdir . $_REQUEST[' | + | |
- | nice_die(" | + | |
- | } | + | |
- | if(!defined(' | + | |
- | define(' | + | |
- | } | + | |
- | // correct paths according to animal and make nice looking in HTML source | + | |
- | if(!defined(' | + | |
- | if(!defined(' | + | |
- | } else { | + | |
- | // don't do anything on the farmer instance | + | |
- | return; | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | ==== How to have subdirectories with the virtual host setup ==== | + | |
- | + | ||
- | You can have subdirectories with the [[#virtual host based setup]] (i.e. without a '' | + | |
- | If you need to make subdirectories within a virtual directory setup work with [[config: | + | ===== Available Methods ===== |
- | < | + | |
- | RewriteRule ^$ subdir/ | + | |
- | RewriteCond %{REQUEST_FILENAME} !-f | + | |
- | RewriteCond %{REQUEST_FILENAME} !-d | + | |
- | RewriteCond %{REQUEST_URI} | + | |
- | RewriteRule ^(.*)$ | + | |
- | RewriteRule ^subdir/ | + | |
- | </ | + | |
- | FIXME I am no rewrite rules expert, can someone please check and correct this (if necessary)? :!: Be careful, this is not fully tested and is already known to cause trouble in some setups. | + | There are different ways to set up a wiki farm. They are described on the following pages: |
- | ==== How to solve the problem with the login ==== | + | Recent: |
- | I had a problem with this tip, when I want to login I got to the main " | + | * Official [[Farms:]] documentation -- the most straight forward setup |
+ | * [[farms:advanced|Advanced setups]] of farm | ||
+ | | ||
- | if(!defined(' | + | Older: |
- | if(!defined(' | + | |
- | | + | |
+ | * [[Redirect farm]], using reconfiguration of VirtualHosts or .htaccess files and a few PHP scripts; | ||
+ | * [[plugin: | ||
+ | * [[Symlink Farm]], conceptually simpler, consists of individual wikis just sharing some directories via symbolic links; | ||
tips/farm.1335014953.txt.gz · Last modified: 2012-04-21 15:29 by joachim aus münchen