Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Moodle migration.

Moodle migration: Difference between revisions

From MoodleDocs
m (Clarified settings)
m (More info and links)
Line 1: Line 1:
Migrating your Moodle site can be divided into these tasks:
There are times when you will need to move your Moodle site from one server to another. This is known as migrating your Moodle site and occurs when you need to change the $CFG->wwwroot value in your Moodle config.php. The process is divided into these tasks:


* '''Upgrade Moodle'''. If you manage your own server, follow the instructions to upgrade Moodle to the version you want, otherwise check if your host has migrated Moodle.
* '''Upgrade Moodle'''. When migrating Moodle it is often a good idea to take the opportunity to upgrade Moodle to the latest version. If you manage your own server, follow the instructions in [[Upgrading | upgrading moodle]], otherwise check if your host can upgrade for you.


* '''Restore a single course'''. You may need to restore a single course from an old site to a new one, especially if you are testing the migration. When restoring a moodle backup file to moodle on a different server than the one used to create the backup, the absolute referenced links to files maybe broken. To fix this problem open the backup-coursename.zip file and edit the moodle.xml file replacing links with $@FILEPHP@$. For example:
* '''Restore a single course'''. You may need to restore a single course from an old site to a new one, especially if you are testing the migration. When restoring a moodle backup file to moodle on a different server than the one used to create the backup, the absolute referenced links to files maybe broken. To fix this problem open the backup-coursename.zip file and edit the moodle.xml file replacing links with $@FILEPHP@$. For example:
Line 9: Line 9:


* '''Migrating a complete Moodle site'''. This involves moving a whole site from one server to another. If you are changing the domain/IP address to the new server you need to do these steps:
* '''Migrating a complete Moodle site'''. This involves moving a whole site from one server to another. If you are changing the domain/IP address to the new server you need to do these steps:
** Backup your current moodle database. This will give you a text file containing the mysql dump.
** Backup your current moodle database by following the instructions in the [[Upgrading | upgrading Moodle]] page. This will give you a text file containing the mysql dump.
** In your moodle directory, change the $CFG->wwwroot variable in the config.php file for the new server.
** Copy the Moodle software code itself to the new server - upgrade the code to the latest version if you can.
** Change any absolute links used for pictures, etc which are stored in the Moodle database. This is because when loading a mysql dump of a moodle server into mysql on another server the absolute referenced links will be broken. This can be most easily fixed with the program '''replace.php'''. After uploading the mysql dump file point your browser to  
** In your (possibly new) moodle directory, change the $CFG->wwwroot variable in the config.php file for the new server.
** Copy the contents of your data directory (check for the value in $CFG->dataroot) to the new server. Check also that permissions remain the same on the new dataroot folder and change the value if you have changed its location on the new server.
** Change your Moodle database. This is needed as links to pictures, files, etc are stored as absolute links and will reference the old $CFG->wwwroot value. So when loading a mysql backup dump of the moodle server into mysql on another server the absolute referenced links will be broken. This can be most easily fixed with the program '''replace.php'''. After uploading the mysql dump file point your browser to  
  http://yourserver.com/admin/replace.php  
  http://yourserver.com/admin/replace.php  
:Enter the url for your old server (http://oldserver.com/) and new server (http://newserver.com/) and it will fix the mysql tables. You will also need to clear out any cached links by restarting your webserver.
:Enter the url for your old server (http://oldserver.com/) and new server (http://newserver.com/) and it will fix the mysql tables. You will also need to clear out any cached links by restarting your webserver.
:'''Warning''': Before using replace.php make a backup of your Moodle database and test this this backup is OK by restoring it to a test install (say on a PC).
:'''Warning''': Before using replace.php make a backup of your Moodle database and test this this backup is OK by restoring it to a test install (say on a PC).
:An alternative is to use the search and replace feature of your text editor (or use a unix tool like sed) to replace the old URL with the new one in the mysql backup file. Once you have done this, restore the database.
:An alternative is to use the search and replace feature of your text editor (or use a unix tool like sed) to replace the old URL with the new one in the mysql backup file. Once you have done this, restore the database.
#sed -e 's/oldserver.com/newserver.com/' mysqldump.sql
:'''Tip''': You may want to check the mysqldump file to see how the old server was referenced.
:'''Tip''': You may want to check the mysqldump file to see how the old server was referenced.
* '''DNS changes'''. You may have had to change the DNS entries for the new Moodle site. If you have done so, it will take some time for the changes to replicate, so be patient.
* '''Internal & External access'''. Lastly, check that the new site can be accessed internally and externally. 
'''See also'''
* [http://moodle.org/mod/forum/discuss.php?d=62959 Changing Moodle URL] forum discussion
* [http://moodle.org/mod/forum/discuss.php?d=57477 Changing site address] forum discussion
* [http://moodle.org/mod/forum/discuss.php?d=76704 Upgrading whilst migrating] forum discussion
[[Category:Installation]]
[[Category:Administration]]

Revision as of 11:29, 31 July 2007

There are times when you will need to move your Moodle site from one server to another. This is known as migrating your Moodle site and occurs when you need to change the $CFG->wwwroot value in your Moodle config.php. The process is divided into these tasks:

  • Upgrade Moodle. When migrating Moodle it is often a good idea to take the opportunity to upgrade Moodle to the latest version. If you manage your own server, follow the instructions in upgrading moodle, otherwise check if your host can upgrade for you.
  • Restore a single course. You may need to restore a single course from an old site to a new one, especially if you are testing the migration. When restoring a moodle backup file to moodle on a different server than the one used to create the backup, the absolute referenced links to files maybe broken. To fix this problem open the backup-coursename.zip file and edit the moodle.xml file replacing links with $@FILEPHP@$. For example:
Replace: http://yourserver.com/file.php/243/ 
With: $@FILEPHP@$ 
When the file is restored it will use the correct file path for the new course.
  • Migrating a complete Moodle site. This involves moving a whole site from one server to another. If you are changing the domain/IP address to the new server you need to do these steps:
    • Backup your current moodle database by following the instructions in the upgrading Moodle page. This will give you a text file containing the mysql dump.
    • Copy the Moodle software code itself to the new server - upgrade the code to the latest version if you can.
    • In your (possibly new) moodle directory, change the $CFG->wwwroot variable in the config.php file for the new server.
    • Copy the contents of your data directory (check for the value in $CFG->dataroot) to the new server. Check also that permissions remain the same on the new dataroot folder and change the value if you have changed its location on the new server.
    • Change your Moodle database. This is needed as links to pictures, files, etc are stored as absolute links and will reference the old $CFG->wwwroot value. So when loading a mysql backup dump of the moodle server into mysql on another server the absolute referenced links will be broken. This can be most easily fixed with the program replace.php. After uploading the mysql dump file point your browser to
http://yourserver.com/admin/replace.php 
Enter the url for your old server (http://oldserver.com/) and new server (http://newserver.com/) and it will fix the mysql tables. You will also need to clear out any cached links by restarting your webserver.
Warning: Before using replace.php make a backup of your Moodle database and test this this backup is OK by restoring it to a test install (say on a PC).
An alternative is to use the search and replace feature of your text editor (or use a unix tool like sed) to replace the old URL with the new one in the mysql backup file. Once you have done this, restore the database.
#sed -e 's/oldserver.com/newserver.com/' mysqldump.sql
Tip: You may want to check the mysqldump file to see how the old server was referenced.
  • DNS changes. You may have had to change the DNS entries for the new Moodle site. If you have done so, it will take some time for the changes to replicate, so be patient.
  • Internal & External access. Lastly, check that the new site can be accessed internally and externally.

See also