Overview
Whilst using MODX Revolution, it is very likely that at some point you will have to copy your setup from one folder to another, or even from one server to another. Here is a straight forward way to make such a move.
Prepare MODX source
Clear the cache and sessions via Manager
On your source installation, log into Manager then do the following:-
- Manage → Clear Cache
- Manage → Logout All Users
Clear the cache via SSH
SSH into your source webserver. Change directory to your source MODX install.
Some cache files will still be there, we want to remove them all. Be careful of this command.
rm -rf core*/cache/*
Dump the database
We want to have a safe copy of our database.
Make sure you have the database name, user and password. These details can be found in core*/config/config.inc.php.
Now dump the database, making sure you replace database_user and database_name with your database name and user name.
mysqldump -u database_user -p database_name > database_name.sql
Set workspace core path
Older versions have the full core path in the workspaces table. To avoid any conflicts, make sure this table contains _{corepath} instead.
Edit database_name.sql
nano database_name.sql
ctrl + v until you reach the end of the file, then ctrl + y until you find the workspaces table.
Change the path of the first record to {core_path}.
ctrl + o to save, then ctrl + x to exit nano.
Backup existing set-up
Plan for the worst by backing-up your current install
Use tar to make a safe backup of your files, just in case!
tar -cvzf backup.tar.gz .
If for some reason you have files or folders that you want to exclude from the backup, you can use --exclude
tar -cvzf backup.tar.gz . --exclude='myfolder'
You can copy or move the archive file into another directory or download it using a ftp program.
Prepare destination
SSH into destination server and change directory to the destination folder.
If there is anything your want to save, archive the contents of the folder using the above steps.
Copy archive to another folder or download it using (S)FTP.
Clean-out destination installation
Only do the following steps if you want a clean install.
Make sure you are inside your destination folder, then remove its contents.
rm -rf *
rm -rf .*
Create new database
Log-in to your server cPanel or similar, then
- DROP the destination database (if one exists).
- Create the destination database.
- Add your database user to the destination database.
Copy source to destination
Copy the source archive file to your destination server or folder.
Update MODX destination
Extract source archive
tar zxvf backup.tar.gz
Update the destination database
Import database
mysql -u database_user -p database_name < database_name.sql
Check settings
After doing any kind of update it is worth checking that your config files contain the correct settings.
nano core*/config/config.inc.php
The following is only necessary on older versions. On newer versions, these config files will be updated automatically when you re-run setup.
nano config.core.php
nano connectors*/config.core.php
nano manager*/config.core.php
Update .htaccess
Make sure your .htaccess file contains the correct settings.
Run MODX setup
Download MODX
You will need to download the setup folder for your version of MODX. This will enable you to run the setup utility to iron out any issues with the transfer of your site.
Find the version of MODX you are using and download it directly onto your server. Make sure you replace the version below with your actual version.
wget https://modx.com/download/direct?id=modx-2.7.3-pl.zip --no-check-certificate --content-disposition
Unzip the file.
unzip modx-2.7.3-pl.zip
For ease of use, rename the extracted folder to something shorter, like modx.
mv modx-2.7.3-pl modx
Now copy the setup folder from the modx directory to your main directory. If rsync is new to you, take a look at this useful rsync guide and consider using the --dry-run
option.
rsync -avP modx/setup/ setup/
Run setup
Depending on how your server is configured, you may need to set the permissions of the setup directory.
chmod -R 755 setup
Visit the setup url - yourdomain.com/setup
Follow the instructions, making sure you select Upgrade Existing Install
Once complete, log-in to the Manager to check that everything is working as it should.
Clean-up
Once working, remove the the unwanted files and directories that we created during this process.
rm modx-2.7.3-pl.zip
rm backup.tar.gz
rm database_name.sql
rm -rf setup
rm -rf modx
Further information
Inspired by Moving your site to a new server.
Here are some of our other MODX articles.