Moodle migration - MoodleDocs (2024)

There may be times when you need to move your Moodle site from one server to another. For example, moving a Moodle site from shared hosting service's server to a dedicated server.

Tip: One common migration mistake is to forget to update the details in the migrated Moodle's config.php file.

Contents

  • 1 Migrating a complete Moodle site - method 1
  • 2 Migrating a complete Moodle site - method 2
  • 3 Other points to consider
    • 3.1 Changed URL image links set to old site
    • 3.2 Upgrade Moodle
    • 3.3 Restoring a single course across servers
    • 3.5 Internal and external access
  • 4 See also

Migrating a complete Moodle site - method 1

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:

  • Maintenance mode. Place your current Moodle site in maintenance mode to prevent any further additions to the Moodle database. Don't let administrators login during the migration as they are not affected by the maintenance mode setting.
  • Backup your current Moodle database. Do this by following the instructions in the upgrading Moodle or Site backup page. This will give you a text file containing the mysql dump.
  • Copy the Moodle software. You will need to copy the Moodle code itself to the new server - upgrade the code to the latest version if you can.
  • Change $CFG->wwwroot. In your (possibly new) Moodle directory, change the $CFG->wwwroot variable in the config.php file for the new server.
  • Copy data directory contents (moodledata). Copy the contents of your data directory (check for the value in $CFG->dataroot) to the new server.
  • Review moodledata permissions. 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 URL. If you have a new URL, you'll need to change this in the Moodle database to the new server. 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. There are two methods of doing this:
(a) The first method changes the Moodle URL using the Moodle script replace.php while your site is currently running just before you backup the Moodle database. 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. Now, take another backup of the Moodle database - this one will have the correct URLs.
(b) The second method is to backup the Moodle database first, then 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. Here is an example sed command:
#sed -e 's/oldserver.com/newserver.com/g' oldmysqldump.sql > newmysqldump.sql
TIP: You may want to check the mysqldump file to see how the old server was referenced.
After changing the URL, restore the mysql database
  • Test the migration. To test the new install, access Moodle using your browser and the new server's URL. When you have tested that a number of links in the courses work, take the new Moodle site out of maintenance mode.

See also: Forum discussion on migrating Moodle's data directory on a Windows system.

Migrating a complete Moodle site - method 2

Do you have shell access on both servers? If so, the following method is a very quick and efficient method to migrate a Unix based site.

It is also useful for creating snapshots or test sites.

  • Set up a new empty database on the new server.

It mean that that you must not open the

http://example.domain/moodle/admin

webpage yet.

  • Place your Moodle site into maintenance mode.
  • Login to shell on the old server.
  • Use rsync to copy moodledata and public_html (or whatever directory your Moodle install is in) to the new server - execute (replacing caps with your details; SOURCE = the directory you want to copy) for each directory:
rsync -av -e ssh SOURCE/ USERNAME@NEW_SERVER.COM:/PATH/TO/DESTINATION/

On the new server you must to setup permissions on moodledata directory and it's subdirectories and files.

Say, on a Debian operating system one can run the command:

hostname:/var/lib# chown www-data:www-data -R moodle/
  • Dump existing database and move and import into database on new server by executing:
mysqldump --allow-keywords --opt -uMySQL_USERNAME -pPASSWORD DATABASE | ssh USER@DOMAIN "mysql -uMySQL_USERNAME -pPASSWORD DATABASE"
  • On the new server, update config.php with relevant details.
  • To fix any internal Moodle links, login to your "new" Moodle install on your new server and use admin/replace.php to search and replace the old uri for the new.

Say:

Search and replace text throughout the whole database

Search whole database for: the.old.moodle.uri

Replace with this string: the.new.moodle.uri

  • Make sure everything is working.

Takes about 15 minutes.

When you are happy all has gone well, set up redirects/make DNS changes if required, take new site out of maintenance mode and "switch off" old site.

Other points to consider

Changed URL image links set to old site

So you built your Moodle Server with a http//192.168.0.1/Moodle address. Then you changed the URL for your site to http://OurMoodle.org/Moodle . You changed the Moodle config file so the CFGs point to the new paths. But your images point to the old url.

One simple, quick solution. Login as admin and put http://OurMoodle.org/Moodle/admin/replace.php in your browser address bar. Use the two form boxes to change http://192.168.0.1/ to http://OurMoodle.org/ .

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.

Restoring a single course across servers

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.

DNS & Masquerading 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. If your server is located behind a firewall, you may also have to change your firewall rules to allow access to the new server. See the masquerading docs.

Internal and external access

If you have a set up where your Moodle site can be accessed via a network and via the internet, ensure you check that the new site can be accessed internally and externally.

See also

Moodle Docs:

Using Moodle forum discussions:

  • Changing Moodle URL
  • Changing site address
  • Upgrading whilst migrating
  • Internal and external access
  • Migrated Moodle to New Server But Can't Login
  • Replace script returns "Service Unavailable"
Moodle migration - MoodleDocs (2024)

FAQs

How do I transfer Moodle from one server to another? ›

Recommended method
  1. Turn on maintenance mode. ...
  2. Backup the Moodle database on the old server. ...
  3. Restore the database backup to the new server. ...
  4. Copy moodledata from the old server to the new server. ...
  5. Copy the Moodle code from the old server to the new server. ...
  6. Update config. ...
  7. Test the copied site.
Jan 11, 2024

How do I speed up Moodle? ›

Boosting Moodle Performance – Tips To Speed Up Your Moodle...
  1. 1: The Basic Tweaks. ...
  2. 2: Get a Managed Moodle Cloud Hosting. ...
  3. 3: Baseline Monitoring. ...
  4. 4: Operating System. ...
  5. 5: Additional Performance Tweaks for Desktops. ...
  6. 6: PHP Accelerators to less the CPU load. ...
  7. 7: Check Memory Limit. ...
  8. 8: Optimize the Performance of Apache Server.
May 29, 2017

How do I change the URL of my Moodle site? ›

Changing the site URL

Using your preferred text editor, open the config. php file. Locate the line in the file that begins $CFG->wwwroot. Update the corresponding value with the new site URL.

How do I put Moodle in maintenance mode? ›

Enabling and Disabling Maintenance mode in Moodle
  1. Log into the Moodle Dashboard.
  2. Go to Site administration > Server > Maintenance mode in the Settings navigation.
  3. On the Maintenance mode page, add the text to the Optional maintenance message block. Select Enable for the maintenance mode. ...
  4. log out of Moodle.
Aug 16, 2021

What is the difference between Moodle cloud and Moodle server? ›

Due to the fact that your site is hosted on the server, you can have total control over who can and cannot access it while using Moodle. However, because Moodle Cloud uses servers from multiple locations, you aren't able to have that much control over access permissions.

Can I use Moodle without a server? ›

Moodle requires a web server (such as Apache or Nginx), a database (such as MySQL or PostgreSQL), and PHP.

Does Moodle have anti cheating? ›

Can Moodle detect cheating? Moodle itself cannot detect whether a student is cheating. However, it can easily be integrated with external tools that allow you to keep a closer eye on your students. It also gives you access to student activity logs through which you can keep tabs on suspicious behavior.

Why is my Moodle so slow? ›

Check your filters. Having too many filters active can have serious effects on server load, especially on lower-end systems. The number of active filters has a direct effect on the perceived latency of your site; that is the time taken for each page impression. Check if any of the filters can be disabled.

What are the server requirements for 5000 users in Moodle? ›

For 5000 asynchronus users a nice system would be dual 2-3ghz with 3GB RAM, some lunuxen or bsd OS, 60GB plus HD, tape backup, UPS or other emergency power source.

What is the URL of my Moodle site? ›

If you don't know the address of your Moodle site, here's how you can find it: Open a web browser (like Chrome or Safari) and go to your school's Moodle site login page. At the top of the page in the address bar, you'll see the URL address of your Moodle site, e.g. “campus.example.edu”.

How do I change my Moodle to https? ›

On a basic Moodle site, it will be simple to set up https. Simply edit config. php and change http:// to https:// in $CFG->wwwroot. However, if you are using a proxy or load balancer, depending on your setup you may need to set $CFG->sslproxy to 1, and not use SSL on the Moodle server.

How do I force login to Moodle? ›

The answer is Yes and it is actually really easy to do in Moodle.
  1. Log into your Moodle site as an admin user, and navigate to the Site security settings option by going to Site administration > Security > Site security settings.
  2. Tick the “Force users to login” option checkbox.
  3. Click the “Save changes” button.
Jun 12, 2023

What is Moodle maintenance? ›

Maintenance mode is for preventing any users other than administrators from using the site while maintenance is taking place, though it's not designed to prevent user access during version upgrades.

How do I reset all data in Moodle? ›

How to reset your Moodle space
  1. On your Moodle space select More and from the drop down menu choose Course reuse.
  2. Expand the Import option and from the list choose Reset.
  3. Expand the list of options and activities and carefully select the data you want to delete and remove.

Can you transfer a website from one server to another? ›

Once you have collected all the data files from your current website and have a secure backup, you can start transferring this to the new Host. You can now upload the compressed website files and information from your old server to the server of your new hosts.

How do I export all users in Moodle? ›

How do I export a list of users? Go to Settings>Site administration>Users>Accounts>Bulk user actions and select the users you wish to export. From the dropdown "With selected users", choose "download" and choose the type of file you wish to download from text, ODS or Excel.

Top Articles
Latest Posts
Article information

Author: Edwin Metz

Last Updated:

Views: 6246

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edwin Metz

Birthday: 1997-04-16

Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

Phone: +639107620957

Job: Corporate Banking Technician

Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.