Multiple sites

This is a brief tutorial on how to create multiple sites with Modx Revolution.  Once setup, this allows the administrator to quickly and easily access and maintain multiple sites from the same manager.  Additionally, it makes launching a preview site a breeze.

Assumptions

You are hosting all the domains on the same server.

For this tutorial you should have a separate folder for each domain:
/var/www/myfirstsite/htdocs/
/var/www/myfirstsite/htdocs/mysecondsite/

or if on separate accounts on the same server. (ie. you wanted to offer a cPanel to each client)
/var/www/myfirstsite/htdocs/
/var/www/mysecondsite/htdocs/

If you happened to have to all your domains pointing to the same folder, then you can follow this tutorial until the last section on updating index.php, and then you will need this domain mapping solution for how to direct the domains to their coresponding context.  Ideally you would want a separate folder on your server for each domain, and this is the way most systems run.

Getting Started

Download Modx Revolution, and follow the general install instructions for your first site. Setup a few pages and test your site to make sure everything is running as you expect.

Creating a second Context

The default context is "web". For this tutorial we will add a new one and call it "site2".  To create this second context do the folowing:

  1. Go to Settings -> Contexts, and click the "create new" button.
  2. Give a short name for the context key, a short description, and then click save.  You will see a second home on the left under resources as seen in the illustration..

    Second Website Context
  3. Create a homepage and under the "site2" context with some brief text on the page like "Site 2 Works Horray!".
  4. Create an error page under the "site2" context.
  5. Duplicate the default template and rename it "template2"

 

Editing Context Settings

The second context takes on all the default settings and behaviors of the primary site, which is great for a quick setup, but there are few things we need to change.

First, right-click on the "site2" home icon and select "edit context". Once the context information loads on the right, click on the "context settings" tab.

Click the "Create New" button, and the "Create New Setting" window pops up. 

Context Settings

You will enter a "Key", "Name" and "value" (as highllighted above) for each of the following:

key | value

site_name | my second site

site_start  | 4 (use the number of your homepage resource)

error_page | 5

http_host | http://www.mysecondsite.com/

site_url | http://www.mysecondsite.com/

base_url | /

default_template | 2

Updating index.php

You will place a copy of index.php into the public root of your second domain folder

i.e. /var/www/mysecondsite/htdocs/ (use the root path for your domain)

On line 89 it says "$modx->initialize('web');"

replace "web" with "site2" (or whatever your context name is).

updating config.core.php

Upload a copy of config.core.php to the public root of your second site.
We want to update the path to your core: /var/www/myfirstsite/htdocs/core

On line 2 it says "define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');" and you would say:

define('MODX_CORE_PATH', '/var/www/myfirstsite/htdocs/core/'); (use the path for your primary site)

Test Site2

You are good to go. Type in your second domain and see if it works. You should see your homepage message: "Site 2 Works Horray!" If it doesn't double check that you have the correct paths in your config file, that your site2 pages are published, and that your context settings keys are correctly configured.

Helpful resources

MODx Revolution multi-Domain Context Installation

Sub domains setup with Modx Revolution

 

Latest Work

Web Design

Having a website that looks good is important, but it is just as important that your site meets your goals and communicates clearly. Believe it or not, you can have your cake and eat it too.