ModX Staging clone done right
This is a little tuto to summarize necessary steps in order to use a staging Modx Revolution server.
original is here: http://www.dzi-neo.net/blog-dzineo/staging-clone.html
** Context **
A production site is hosted on a pro or semi-pro solution where you have sufficients rights and means to be able to do some ** SSH ** manipulations, or you have an administration panel such as ** Plesk. **
And
you are using the ** Babel multilingual solution **. (May be all cases won't be covered).
The goal is to clone your full server into another location (mostly on the same server, and, usually, making it accessible through a subdomain).If you have a production website and are planning major site changes, consider setting up a staging site — a separate location on the server where you can conveniently update and test a copy of the site before putting it into production.
** Here's the Plesk documentation excerpt: **
Decide where you want to host the development copy and prepare the development environment. You can choose to host it in the same webspace, in a separate webspace on the same server, or upload it to an FTP account on another server.
If you choose the same webspace, then you first need to set up a new website by adding a domain or a subdomain.
Those steps will be:
Make a copy of the website and place it in the staging environment.
Make copies of the databases used by the site and deploy them in the staging environment.
Change database connection settings in the scripts to point at the databases in the staging environment.
** Using Plesk to complete #1 and 2 tasks: **
To set up a domain for staging purposes:
Go to the Websites & Domains tab.
Click either Add New Domain or Add New Subdomain.
Here we will proceed to a sub domain named "dev01" to use the clone at dev01.myserver.tld
To make a copy of website files:
Go to the Websites & Domains tab and find the name of the website you want to copy.
Click Website Copying.
To copy website files to the document root of an existing site:
Select the option Website in Plesk.
Select the destination site from the Site name menu.
Specify what to do with the files that might already be present in the destination directory.
To copy website files to an FTP account on this or another server:
Select the option FTP storage.
Specify the server's host name and credentials for connecting to the FTP account.
In the FTP connection method field, leave the Active mode option selected. If Plesk fails to connect to the external FTP account, select the Passive mode option here.
Click OK.
note: classic FTP transfer are not a good idea with large numbers of files like with Modx files tree.
** Using SSH: **
Once loged-in do the necessary cd /all/the/way/down/to/your/folder/ABOVE/httpdocs/
rsync -a "YourHttpdocs" "/whereis/your/subdomain/folder
This will create an "archive" copy preserving rights and ownerships. It might take pretty long time (a few minutes). Then a last stuff to do is to re chown the new httpdocs folder itself to the correct owner (wich is now tipically "root" and should go back to the same as the original source).
for exemple:
chown -R www-data:www-data modx-staging
** To make a copy of a database from the Plesk-managed server: **
Go to the Websites & Domains tab > Databases.
Click Copy in the databases list for the database you want to copy.
Specify the following:
Destination database server. You can select the same Plesk-managed database server, or a database server located elsewhere. For an external database server, specify the host name or IP address, and access credentials: the username and password of a database management system user authorized to create new databases and database tables.
Destination database. You can choose to create a new database or copy the data to an existing database.
Create a full copy. Leave this option selected to copy the database structure and all data.
Click OK.
The copy of the database will be deployed on the destination server.
I strongly suggest to use another SQL user for this number2 DB.
Modify the site's scripts in the staging environment so that they connect to the copied database.
To edit all concerned files
When moving a ModX site it's always at least mandatory to edit the 2 config.inc.php files found at the web site folder and under the core/config folder.
Here you'll have to match the DB names, user for connection and a few pathes to adapt them to the new location. just look at thos file in your favorite code editor and perform a search/replace.
Well, unfortunatly this won't probably be enought because depending on the different components you are using chances are high that there's some other setup files somewhere that needa be touch either.
** Here's a very good tips from this codewall article ** : https://coderwall.com/martinseener I just paste here:
... to find all places, where the hardcoded path, for ex. /var/www/modx-production/ is being used in the staging environment. We will use good old linux tools for that
grep -r "modx-production" /var/www/dev01.myserver.tld/
you'll then have a list of files that need to be touched. In order to be efficient with this method the suddomain folder must NOT be under domain folder, otherwise you won't have any significant keyword to search for.
** Now guess what? **
Clear the cache folder under core/ folder, or you may delete this cache folder because it will be recreated by modx.
At this point I prefer re execute a setup
** Go to setup to fix every stuff potentially missed. **
I recommend not to remove the setup folder once an installation is done but rather prefer rename it with something including the ModX release number. This way you have only to rename it back "setup" and go to its url to execute an advanced procedure to check the DB connection and collation and finish the reinstallation process to fix any glitches.
Once it's correctly completed, you're done and your staging server is almost ready, so its «/manager» url should correctly respond. Basically the .htaccess file at the the root of the site should not have to be edited, but it depend of how you managed your Babel stuff.
** Adapt the ModX contexts **
Login as a manager and go to your System/system setup menu
check the core | site parameters to edit the site name and turn it into «yournamedev» or something. This will prevent any confusion when you'll geet back in a modx Manager and avoid to edit the production site by mistake.
Now go to Contexts menu and edit the default one plus any other context reflecting the other languages you are dealing with.
right click on each oth them to edit, go their parameters tab, right click on the site url parameter and adapt the path to match your staging server.
SAVE
Now, enjoy your clone and make some magic with it!