Moving Site To Another Location

From MODx Wiki
Jump to: navigation, search

This tutorial is based on a typical scenario, which is developing on XAMPP locally (Win XP Pro) and deploying on a typical LAMP server environment. The same steps will work for any source server with little or no modification, unless to the .htaccess file or the method of accessing your database.

It's not required, but it's a very good idea to turn off Friendly URLs (FURLS) in the Manager, if you have them on, and rename .htaccess to ht.access before doing any of the steps below. Do the reverse as your last step after everything is working at the new location (rename ht.access to .htaccess and turn on FURLS). It takes a big potential source of confusion out of the picture during the transition.

Before moving your site, make sure that you have the following line in the <head> section of all your templates:

For MODx Evolution:

   <base href="[(site_url)]" />

For MODx Revolution:

   <base href="[[++site_url]]" />
  1. Install the site locally, renaming and editing the .htaccess file to indicate the subdirectory you are deploying your site into in the test environment, as in the following example with a local development copy of the MODx CMS site at /localhost/modxcms/:
    # For full documentation and other suggested options, please see
    # http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
    # including for unexpected logouts in multi-server/cloud environments
     
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /modxcms
     
    # Fix Apache internal dummy connections from breaking [(site_url)] cache
    RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
    RewriteRule .* - [F,L]
     
    # Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^example\.com [NC]
    #RewriteRule (.*) http://example.com/$1 [R=301,L]
     
    # Exclude /assets and /manager directories from rewrite rules
    RewriteRule ^(manager|assets) - [L]
     
    # For Friendly URLs
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
     
    # Reduce server overhead by enabling output compression if supported.
    #php_flag zlib.output_compression On
    #php_value zlib.output_compression_level 5

    Don't forget to rename or copy the ht.access file to .htaccess in the /manager folder to turn off the RewriteEngine for that folder.

  2. After developing the site locally (using all relative paths from the site root, to keep it portable), make a copy of .htaccess and call it .htaccess.local, editing the RewriteBase in the .htaccess file for the remote deployment location as appropriate (usually removing the subdirectory path, just leaving the /). The .htaccess file in /manager should be left as it is.
  3. Then make a copy of manager/includes/config.inc.php as config.local.inc.php, and edit config.inc.php with the remote database connection settings for the deployment server (the remote db must be already created and ready to use; make sure it's created with the proper character set and collation defaults).
  4. Clear the site cache (Site -> Clear Cache).
  5. Copy the /manager, /assets, /index.php, and /.htaccess folders and files to the target server (you can optionally exclude *.local.*). If this is an upgrade and not a new installation, make sure to save your remote site's /assets folder first, then you can re-upload all of your existing content, such as images and templates, if the upload has overwritten any of it. Upload the /install folder from the original unzipped archive.
  6. Unless you are in an environment where the webserver runs as the same username with which file ownership is attributed on the target server, you will need to change permissions on the following directories/files to 777:
    • /assets/cache (and all files ending with .php in this directory)
    • /assets/images
    • /assets/files
    • /assets/flash
    • /assets/media
  7. Dump the local DB contents (use Tools -> Backup in the MODx Manager, or any MySQL client such as phpMyAdmin) and then import the SQL dump in the target DB on the remote server (most hosting environments use phpMyAdmin for this). You will probably want to empty any log tables (Reports -> System Events and Reports -> Manager Actions) before backing them up, or else you'll have rows and rows of log data useless to your new server.
  8. Access the remote manager's Tools -> Configuration and correct the paths for the resource browser (File Base Path and File Browser URL in Tools -> Configuration -> Interface & Features tab; the URL is probably set to "assets/" and should continue to work) and the filemanager (File Manager Path at Tools -> Configuration -> File Manager tab)
  9. Run the installer on the new site. Point your browser at http://yoursite.com/install and select Upgrade install. Important! Uncheck the options for installing the sample web site and all the other components (which you should already have in your database).
  10. Test the remote site. It should be working just the same as your local development site.
Personal tools