Steps in brief
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).
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).
Click the server tab at the top.
Click the "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.
Finally, click the 'Save changes' button.
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".
Once you have downloaded and installed FileZilla, open it up and enter your current host's FTP details across the top, then click "Quickconnect".
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.
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.
In the left pane, open up the Moodle backup (moodle3backup) folder that you created earlier.
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".
You should now see a list of transfers appear at the bottom of FileZilla.
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.
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.
Once connected, in the right pane, look for a folder called "moodledata".
In the left pane, make sure you have your moodle3backup folder open. Right click on the moodledata folder and click 'Download'.
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.
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).
You should now see tables such as (but not limited to):
(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.
Click the 'Export' tab at the top of the page.
Then click the 'Go' button.
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).
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).
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.
Click the "Choose file" button and select the database backup you made in step 3 earlier.
Click the "Go" button to start the import.
Once complete, you should see a message along the lines of "Import has been successfully finished, XXXX queries executed.).
You can now close PhpMyAdmin.
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).
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):
$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.
OPTIONAL : If you are changing your moodle domain, you will also need to change the line:
$CFG->wwwroot = 'http://yourwebsite.com';
to match your new domain name/URL of moodle
$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.
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.
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.
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.
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'.
At the bottom of your screen, you should see your moodledata folder being uploaded.
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.
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.
In the left panel, open up your moodle backup folder.
You should now have an empty public folder on the right hand side open and your moodle3backup folder open in the left pane.
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'.
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.
Once the files have uploaded, you can close FileZilla.
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:
Then send the below message to the company who you purchased your domain name with (domain registrar):
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.
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.
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.
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.
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".
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.
You should then be redirected to your main Moodle admin dashboard.
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.
Then select the "server" tab at the top.
Click the "Maintenance mode" hyperlink.
Select "disable" from the "Maintenance mode" dropdown and click the "save changed" button.
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.