Replacing an Existing MODX Site

MODX logoIt’s a common task to have to replace (not upgrade) an existing site with a MODX site. Maybe you’re converting an Evolution site to Revolution, or converting a WordPress site to MODX Revolution. In any event, you don’t want the site to be down for days or weeks while you build the new site. What’s the best way to handle this?

There are actually a number of solutions to this problem. One solution is to build the new site in a subdirectory on the server. When it’s finished, you can either copy it to the root, leave it where it is and point the site to it in cPanel, or (if the original site was in a subdirectory) just rename the two subdirectories.

Another way to go is to build the new Revolution site on top of the existing site, by renaming files and directories. This always seems to confuse me, but it may work for you.

A third way is to create the new site on a localhost install and transfer it to the live server when finished. This can seem like an attractive alternative, but I’ve found it increasingly unsatisfactory. It often involves moving many files in both directions and configuring two different installs with totally different root paths. There are a lot of moving parts, and it’s easy for things to go very wrong. In addition, it’s difficult to implement this method without the old site being down for an indeterminate amount of time.

My Method

This method works really well for me. The old site is down for just a few seconds before the new site is up and it only takes a few seconds to revert to the old site if there are problems with the new one. It does require that all your sites be in subdirectories as recommended in the previous article.

In nutshell, you just create and work on the new site in a subdirectory. When it’s finished, you edit four files, rename the original subdirectory and the new one, and you’re done. See the previous article for more information on having a MODX site in a subdirectory.

I just did this recently for an Evo to Revo conversion. It worked really well and I didn’t even have to create a virtual host, although in my case, the client’s original site was in a subdirectory I’ll call
clientSite, reachable at clientSite.com:

Installing

  1. Create a subdirectory called clientSite2 – it should be accessible with clientSite2.yourdomain.com.
  2. Copy the MODX files to the clientSite2 directory, or use one of the installer scripts mentioned on the Forums there.
  3. Put this in the browser’s address bar: http://clientSite2.yourdomain.com/setup. (you may need to create the database first)
  4. If Setup goes well, let it delete the Setup directory
  5. Once MODX is installed, you should be able to log in by going to http://clientSite2.yourdomain.com/manager/

Building the site

This part is all done the normal way. All your templates need this tag in the head section:

[code language=”html”]
<base href="[[++site_url]]"/>
[/code]

If, for some reason, that doesn’t work (internal links fail), use this one:

[code]<base href="http://clientSite2.yourdomain.com/"/>[/code]

But remember to change it when you move the site.

All internal links on the site should be in the form of link tags:

[code]<a href="[[~12]]">Some Text</a>[/code]

The number in the link tag is the Resource ID of the resource it points to (visible in parentheses next to the page title in the Resource Tree at the left side of the Manager).

Putting It in Place

When the site is ready to replace the original, this is all you need to do:

  1. (optional) If you customized the base href tag, change the href to “[[++site_url]]”
  2. Log out of the dev. site
  3. Delete all files in the core/cache directory
  4. In cPanel’s file manager, edit the following four files. Change all instances of clientSite2.yourdomain.com to just
    clientSite.com (the address of the original site) — be sure you get them all in config.inc.php:

    • config.core.php (MODX root)
    • manager/config.core.php
    • connectors/config.core.php
    • core/config/config.inc.php
  5. Modify the .htaccess file’s Rewrite Base line if necessary
  6. Rename the clientSite directory to clientSite.old (site goes down at this point)
  7. Rename the clientSite2 directory to clientSite (site comes back up as the new site)
  8. Important: delete all files in the clientSite/core/cache directory
  9. If you customized the base href tag in the template(s) and haven’t fixed it yet, you’ll need to change it now or internal links will not work

At this point, the newly developed site should be working fine at original address. If not, double-check the paths in the four config files you modified.

You can delete the old site (in the clientSite.old directory) now, but I like to leave it there for a while to make sure everything is OK with the new site and to serve as a backup. I modify the index.php files in the root and Manager folders by adding this at the top just below the starting php tag:

[code language=”php”]
<?php
die(‘Unauthorized’);
[/code]

Don’t forget to remove that line if you end up having to restore the old site.


For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or
better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , | Posted under MODX, MODX | RSS 2.0

Author Spotlight

Bob Ray

Bob Ray is the author of MODX: The Official Guide and over 30 MODX add-on components. He hosts Bob's Guides, a source of valuable information for MODX users, and has been very active in the MODX Forums with over 19,000 posts.

Leave a Reply

Your email address will not be published. Required fields are marked *