// you’re reading...

CMS

MODx Revolution multi-Domain Context Installation english

With the introduction of the new “Revolution” release of the MODX Content Management System the developer team has implemented native support for serving multiple domains with one installation of the MODx software. Up to date such a constellation was only possible with workarounds and those so called solutions were not always 100% bullet proof under all aspects of web development.
In the following I have written a multiple domain tutorial for MODx Revolution and going with that I say thank you to Jason Coward (opengeek) who has supported my first multi-domain install and numberless other MODx topics with a lot of his “good open soucre energy”.

Diese Anleitung gibt es auch auf Deutsch.

Presumptions

  1. This tutorial is based on the assumption that all domains that shall be served by this MODx Revolution installation are pointing to one and the same directory/the same document root on your web server, e.g. /var/www/localhost/htdocs or /var/www/localhost/modxrevomulti or a corresponding path on other operating systems.
  2. This tutorial uses the domains modx-templates.com, ffmwireless.de, thesearchgoeson.com for demonstration, their usage might change in the future.
  3. Versions: the first succesful multi-domain test I installed with Revolution beta-2, for this tutorial a beta-5 SVN is used. With future versions of MODx Revolution the version number should not play a role any more.
  4. Furthermore I exclude the discussion of author rights between multiple contexts because I don’t need them :-) – for your project you might want to check this before you start.
  5. This tutorial presumes you have a plain MODx Revolution installation ready and haven’t made any bigger changes or none at all. If not: here you can find the necessary MODx installation files.
  6. I have changed the System > System Settings to activate the friendly_urls and corresponding settings but don’t assume this is mandatory for a multi-domain installation.

Contexts

The complete architectural redesign of MODx Revolution introduces under the keyword “contexts” the concept of encapsulating the elements of each website (or other elements) into a separate area in the MODx internal data structure – into a context.

After the basic installation of a MODx Revolution package the Manager looks as follows (I have added some example documents):

MODx Revolution Basisinstallation

Picture 1: MODx Revolution default installation

You see the default Context web which is always installed with MODx and the 3 documents “Start”, “MODx Revo … Tutorial” and “Error 404 page”.

If you now navigate to the overview of Contexts in MODx (Menu System > Contexts),

MODx Contexts view and "Create contexts" dialog

Picture 2: MODx Contexts view and "Create Context" dialog

you can find 2 entries: web, the already mentioned default-Context for the first website and mgr, the MODx Manager that plays a special role and holds the MODx administrational backend.

To these Contexts we now add two more, one for each domain we want to serve additionally in the future. After the creation of the two additional Contexts the MODx-Manager looks like this

MODx Contexts für zusätzliche Domains hinzugefügt

Picture 3: MODx Contexts for additional domains have been added

Now we furthermore add some standard documents to the Contexts, you need at least one start page/index page per domain/context and also one error page for each.
Names and descriptions are not important, we will only need the document IDs for the later completion of the Contexts configuration. After adding the documents for each of your domains the document structure should look similar to this

MODx-Manager nach der Einrichtung der Standarddokumente für jeden Context/Domain

Picture 4: MODx-Manager after adding the default documents for each context/domain

Completion of the additional Contexts configuration in MODx Manager

Contexts can be configured completely independent but in the first place they inherit all known website-settings from the base installation and hence we will (have to) change some of the Contexts’ parameters.

Open the Contexts view again via System > Contexts and what you will likely see is the view of Picture 3 above.
Right-click the Context you want to edit (I start with “thesearch”) and choose “Update Context” from the upcoming menu. The Context is now opened in the editing mode and you will have to switch to the “Context Settings” tab, then you will see the following

MODx Context Bearbeiten Ansicht

Bild 5: MODx Context editing mode

You now add, one after the other, the following configuration keys by clicking on Create new

key  |  value

http_host  |  www.thesearchgoeson.com
site_url  |  http://www.thesearchgoeson.com
base_url  |  /
site_name  |  MODxCMS TheSearchGoesOn test
site_start  |  6
error_page  |  7  [optional, aber empfehlenswert]
default_template  |  3  [optional, wenn Sie mehrere templates vorbereitet haben]

Besides key & value you also have to fill out the field name in the dialog, there you can fill in whatever seems fitting and the other fields can stay as predefined or – where you like it – can be filled with additional descriptions. The values for site_start and error_page you can see in picture 4 or according to the settings on your web page.

When MODx finds an already existing value for the field name in the shipped language files, your manually added name might now be shown (and this behaviour might change in the future). After all settings/keys are done the Context parameters look as follows (sorted by key)

MODx Context konfiguriert

MODx Context configured completely

Repeat the last step for all domains/contexts you want to use, I have meanwhile also configured keys for the Context ffmwireless - and so we can proceed to the last step of this tutorial.

Mapping of domains and contexts in the index.php file

In the end follows a last simple step in the index.php file in your MODx root-directory (= thedocumentroot fo your webserver for this MODx installation), you can see the file contents here as originally shipped with MODx Revolution.

Delete or comment line 89

//$modx->initialize('web');

by adding the two slashes “//” in front and add the following code-block directly below the line, of course changed for your domain names and the number of domains you want to run with this MODx Revolution installation

/* setup for multiple domains */
switch(strtolower(MODX_HTTP_HOST)) {
   case 'www.modx-templates.com:80':
   case 'www.modx-templates.com':
      // if the http_host is modx-templates.com, switch the context to web
      $modx->initialize('web');
      break;
   case 'www.ffmwireless.de:80':
   case 'www.ffmwireless.de':
      // if the http_host is ffmwireless.de, switch the context to ffmwireless
      $modx->initialize('ffmwireless');
      break;
   case 'www.thesearchgoeson.com:80':
   case 'www.thesearchgoeson.com':
      // if the http_host is thesearchgoeson.com, switch the context to thesearch
      $modx->initialize('thesearch');
      break;
  default:
      // by default / if no other rule can be applied, load 'web' context
      $modx->initialize('web');
      break;
}

After your code-block should only be the follwing lines from the original code

/* execute the request handler */
if (!MODX_API_MODE) {
    $modx->handleRequest();
}

the complete new MODx indx.php file you can finde here (lines 91 – 112 have been changed).

That’s it, you made it – MODx is running with multiple domains and you can apply the tutorial for even more domains/contexts or other constellations!

Discussion

Trackback URL for this post: http://www.h-quadrat.com/techblog/111-modx-revolution-multi-domain-context-installation-english.php/trackback

Comments are disallowed for this post.

  1. […] This document is also available in english. […]

    Posted by MODx Revolution multi-Domain Context Installation | H-Quadrat IT TechBlog | Beratung ¤ Webdesign ¤ Content Management Systeme ¤ [web]Entwicklung ¤ Hosting ¤ IT Services Delivery in Rüsselsheim | November 30, 2009, 04:29
  2. […] This post was mentioned on Twitter by sharkbait and hquadrat, hquadrat. hquadrat said: @modxcms Multi domain installation tutorial with MODx Revolution http://is.gd/57zvx #MODx #MODxCMS #iworker […]

    Posted by Tweets that mention MODx Revolution multi-Domain Context Installation english | H-Quadrat IT TechBlog | Beratung ¤ Webdesign ¤ Content Management Systeme ¤ [web]Entwicklung ¤ Hosting ¤ IT Services Delivery in Rüsselsheim -- Topsy.com | November 30, 2009, 11:05
  3. […] heck of a lot easier to do in Revolution.  And it was; it took less than an hour to evaluate three different ways of running multiple virtual hosts, and settle on the one I liked the […]

    Posted by Why I’m starting with MODx Revolution instead of Evolution « The CMS less traveled | February 6, 2010, 00:38