Website Migration Guides

A simple free resource for website migration

HOW TO MIGRATE Moodle 3 TO A NEW HOST / SERVER

Steps in brief

  1. Turn on maintenance mode.
  2. Backup moodle database on the old server.
  3. Backup the moodle public folder.
  4. Backup the moodledata folder.
  5. Update the moodle config.php file with the new database details, $CFG->wwwroot and $CFG->dataroot.
  6. Upload the moodle files/folders to the new site.
  7. Log into the admin and make sure that it loads correctly.
  8. Run search and replace tool to update urls (if domain has changed).

moodle Detailed Guide

So you're looking to move Moodle to a new hosting company? Well you're in the right place. The below guide was completed using moodle 3.6 but the steps would be the same for all 3.X versions (although the admin may look slightly different in style).

1. Turn on Moodle 3 Maintenance mode

The first step is to stop anyone else using the website. This is to stop visitors adding data to the server (which in turn could be lost when the moodle site is copied over to the new server).

Turn on maintenance mode : site administration

Click the server tab at the top.

Maintenance mode server tab

Click the "Maintenance mode" link.

Maintenance mode link

From the Maintenance mode dropdown, click "Enable". If you would like to display a message to your visitors, enter this in the "Optional maintenance message" box.

Maintenance mode dropdown

Finally, click the 'Save changes' button.

save changes

2. Backup Moodle 3 files / folders

The next step is to backup the Moodle 3 files / folders that are stored on your server. Whilst some hosting companies provide a 1 click backup feature or automatic backup feature, in this guide we will use FTP instead. The reason for this is two fold:

1) Every host provides FTP access.
2) We only need to backup the moodle data (most 1 click backups will backup everything on the host including non moodle data which is not what is required).

The first thing you will need to do is get yourself a copy of a FTP client. At Website Migration Guides, we prefer to use FileZilla (it's free and works without any issues). FileZilla can be downloaded from filezilla-project.org.

You will also need to create a folder on your computer where you can store your Moodle 3 backup. In this guide, we will create a folder called "moodle3backup".

2.1 Download Moodle 3 files/folders

Once you have downloaded and installed FileZilla, open it up and enter your current host's FTP details across the top, then click "Quickconnect".

moodle ftp connect

Once connected, look for your public folder (usually called public_html or htdocs) on the right pane and double click on it to open it.

moodle public_html folder

You now need to find your Moodle files/folders. These folders / files include (but are not limited to):

Depending on where you installed Moodle to, you may already see these folders (and others) in the right hand pane. If you do, you can continue to the next step.

moodle files and folders

TIP : If you do not see your Moodle files/folders then you may have installed Moodle into a sub folder. You can usually work out what the folder is called by the URL your students have to type in to load your Moodle site. For example, if your students have to visit www.your-website.com/learning then you would need to look for a folder called 'learning'.

In the left pane, open up the Moodle backup (moodle3backup) folder that you created earlier.

moodle backup folder

You should now have all of your Moodle 3 files / folders open in the right pane and your backup folder open in the left pane.

Select all of the Moodle files/folders on the right (for Windows PC, click any file then press CTRL+A to select everything) so that they are highlighted in blue, then right click on one of them and click "Download".

download moodle 3 backup

You should now see a list of transfers appear at the bottom of FileZilla.

downloading moodle

Keep an eye on the 'Failed transfers' tab. If any files fail, you will need to restart them.

Once all of the files / folders have been downloaded, you can close FileZilla and move onto the next step.

2.2 Download Moodle 3 'moodledata' folder

The next step is to download your moodledata folder. This is usually located just outside the public folder.

Open up FileZilla again and connect to your hosting.

moodle ftp connect

Once connected, in the right pane, look for a folder called "moodledata".

moodledata folder

In the left pane, make sure you have your moodle3backup folder open. Right click on the moodledata folder and click 'Download'.

download moodledata

As before, wait until the download has completed and check for any failed transfers.

TIP : If you have a large moodledata folder, you can download the folders inside the moodledata folder one at a time. To speed things up you can skip copying the CONTENTS of the following folders:

However, you must create the folders manually in your moodledata backup folder.

downloading moodledata folder

3. Backup Moodle Database.

The easiest way to backup the moodle database is to do it via PhpMyAdmin. PhpMyAdmin is a free program that all hosts that are running a MySQL database will provide. Usually this can be found in your hosting control panel but if it isn't, copy and paste the below to your hosting company in an e-mail / support ticket.

Hello, can you please confirm how I can open my moodle database in PhpMyAdmin / how to access PhpMyAdmin?

If you do not know what your database is called, you can find it in the config.php file in your backup. Simply open up the config.php file with a plain text editor (e.g. Notepad) and your database will be listed next to "$CFG->dbname = "

Once you have PhpMyAdmin open, select your moodle database from the left (if it is not already selected).

select moodle 3 database

You should now see tables such as (but not limited to):

mdl_analytics_indicator_calc
mdl_analytics_models
mdl_analytics_models_log
mdl_analytics_predictions
mdl_analytics_prediction_actions
mdl_analytics_predict_samples

(yours may have a different prefix e.g. instead of 'mdl_' , it may say something else).

If you do not see tables like the ones above (or the ones in the picture below) then you are not in your Moodle database.

moodle database tables

Click the 'Export' tab at the top of the page.

export moodle database

Then click the 'Go' button.

go export

TIP : If you have a large moodle 3 database, you may wish to also download the database backup as a zip file. To do this, click the 'Custom' radio button, then click 'zipped' from the 'Compression:' dropdown then click the 'Go' button.

Save the provided SQL file (or zip file) to your computer (it will be needed later when restoring your site).

4. Restore Moodle database

Now that you have a full backup of your moodle 3 files / folders, moodledata folder and database, it's time to start restoring them on the new host.

On your new host, create a new MySql Database and make a note of the database name, database username, database password and database host (if you do not know how to create a database, see our other guides here for the most popular control panels or contact your new host for instructions).

Once you have created your new database, open it up in PhpMyAdmin and select it from the left menu (if it is not already selected).

select new moodle 3 database

You should see a message saying "No tables found in database.". If you do not see this, you are not in your new database.

Click the 'Import' link at the top of the page.

import moodle 3 database

Click the "Choose file" button and select the database backup you made in step 3 earlier.

Choose moodle file

Click the "Go" button to start the import.

Go Import

Once complete, you should see a message along the lines of "Import has been successfully finished, XXXX queries executed.).

Import has been successfully finished

You can now close PhpMyAdmin.

5. Edit Moodle config.php file

Before you can start restoring your Moodle files / folders, you need to make some changes to the config.php file in your Moodle backup (moodle3backup) folder.

On a Windows PC, open your Moodle backup folder, locate the config.php file and open it up with a non rich text editor (e.g. Windows Notepad).

Moodle config file

CAUTION : Do not use a rich text editor such as Microsoft Word as this will corrupt the file. Only use plain text editors such as Windows NotePad or the opensource NotePadd++

Once opened, you will need to edit the following lines to match your new mysql database login details (from step 4):

Locate:

$CFG->dbhost    = 'aaaaaaa';

(yours will have something different to aaaaaaa), and update aaaaaaa to match your database host (usually localhost).

Locate:
$CFG->dbname    = 'bbbbbb';

(yours will have something different to bbbbbb), and update bbbbbb to match your database name.

Locate:
$CFG->dbuser    = 'cccccc';

(yours will have something different to cccccc), and update cccccc to match your database username.

Locate:
$CFG->dbpass    = 'dddddd';

(yours will have something different to dddddd), and update dddddd to match your database password.

Finally, locate the line:
$CFG->dataroot  = '/path/to/moodledata';

(yours will have something different to /path/to/moodledata).

This line will need to be updated with the full path to your moodledata folder.

For security reasons, the moodledata folder should always be stored outside the public folder (e.g. public_html) to stop it being accessible online. If you do not know your new host's full path, send your new host the following message:

Hello, can you please confirm what the full path to my public folder is on my hosting account? Can you also confirm what my public folder (the location where I need to upload my website to) is called? e.g. public_html, htdocs etc.

The above should result in your new host providing you with something like:

"Your full path is '/usr/server98/path/public_html' and your public folder is called 'public_html'."

To get the path of your moodledata folder, you would simply replace the public folder (e.g. public_html) with moodledata.

e.g. using the above example, your moodledata folder would be '/usr/server98/path/moodledata' and the line would look like:

$CFG->dataroot  = '/usr/server98/path/moodledata';

Update the line in your config.php then save file.

5. Upload moodledata folder

You will now need to upload your moodle data folder (to the same location you specified above). To do this, open up FileZilla and enter your new host's FTP details across the top, then click Quickconnect.

new hosts ftp

The next step will vary slightly depending on your host. In the right pane, locate your public folder (e.g. public_html) but do NOT open it.

public_html folder

The reason you do not open the public folder is because you need the moodledata folder to sit outside the public folder. If you opened the public folder, the moodledata folder would be uploaded inside it (in the next step). By not opening it, the moodledata folder will sit alongside the public folder (in the same directory).

In your left pane, locate your moodledata folder but do NOT open it.

moodledata folder filezilla

You should now have your moodledata folder listed on the left and your public_html folder listed on the right. Both should NOT be open.

Right click on your moodledata folder and select 'Upload'.

upload moodle data folder

At the bottom of your screen, you should see your moodledata folder being uploaded.

uploading moodledata folder

Make sure to check the Failed Transfers tab for any files that did not upload correctly.

Keep FileZilla open as you will need it in the next step.

6. Upload Moodle files / folders (public)

Now that you have restored your database and moodledata folder, the next step is to upload the moodle backup you made in step 2 earlier.

In FileZilla (whilst connected to your new host), open the public folder (public_html / htdocs) in the right pane.

public-folder new host

In the left panel, open up your moodle backup folder.

moodle backup upload

You should now have an empty public folder on the right hand side open and your moodle3backup folder open in the left pane.

file list

Select all the files and folders (Windows users press CTRL+A) from the left pane (moodle3backup) to highlight them all in blue then right click on one of them and select 'Upload'.

upload moodle backup data

You should now see your Moodle files and folders being uploaded. Once completed, check the failed transfers tab for any files that have failed. If any have, make sure to re-upload them.

uploading moodle data

Once the files have uploaded, you can close FileZilla.

7. Point your domain to your new host

At this stage you will want to be able to load your domain with your new hosting. The easiest way to do this is to update your domain's nameservers to point to your new hosting. If you are not sure how to do this, send the below message to your new host:

Hello, I need to update my domain's nameservers to point to my hosting with you. Can you please confirm what these are?

Then send the below message to the company who you purchased your domain name with (domain registrar):

Hello, Can you please provide step by step instructions on how to update my domain's nameservers?

Once your domain registrar has updated your nameservers (or once you have), you will need to allow some time for the changes to filter out (propagate) online. This can take up to 48 hours but is usually under 4.

8. Open your Moodle website

Once you have updated your nameservers, open up your moodle website's admin area and if everything has been done correctly, it should load up as normal.

If you get the error message "Error: Database connection failed. It is possible that the database is overloaded or otherwise not running properly. The site administrator should also check that the database details have been correctly specified in config.php", you have entered the incorrect database details in your config.php file.

It is possible that the database is overloaded

If you get the error message "Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.", you have entered the incorrect path to your moodledata folder in the config.php OR you have not uploaded the moodledata folder OR you have not uploaded the moodledata folder to the correct location e.g. alongside the public folder and not inside it.

9. (optional) Update URLs if you are changing your domain

If you are moving to a new domain e.g. from www.domain1.co.uk to www.domain2.co.uk, you will need to run the update script to update . Moodle comes pre-installed with a script to do this .

Open up your moodle admin area and log in. Next, open up http://yourmoodlesite.org/admin/tool/replace/index.php in your browser (replace yourmoodlesite.org with your domain name).

You should see a "Search and replace text throughout the whole database" page.

Search and replace text throughout the whole database

In the "Search whole database for" box, enter your old domain name e.g. https://olddomain.com. In the "Replace with this string" enter your new domain e.g. https://newdomain.co.uk. Tick the "I understand the risks of this operation" button then click "Yes, do it".

DB search and replace

You will then see a lot of "UPDATE WHERE" SQL queries being run. Once complete, two green boxes will appear stating "Replacing in html blocks..." and "...finished". At this stage, click the "Continue" button.

...finished

You should then be redirected to your main Moodle admin dashboard.

1. Turn off Moodle 3 Maintenance mode

The last step is to turn off maintenance mode. To do this, log into your Moodle admin and click the "site administration" link on the left.

Turn on maintenance mode : site administration

Then select the "server" tab at the top.

Maintenance mode server tab

Click the "Maintenance mode" hyperlink.

Maintenance mode link

Select "disable" from the "Maintenance mode" dropdown and click the "save changed" button.

Maintenance mode disable

Comments

If this guide has helped you or if you feel it could be improved, please let us know in the comments below.

Hi, did this site help you?

I'm John and this little website is my online side project. It isn't sponsored by any company and I rely solely on donations to pay the hosting fees. If this site has helped you please consider making a small donation using the link below.

Thanks again and happy surfing.