Changing name and IP of moodle server

Changing name and IP of moodle server

by Tim Huff -
Number of replies: 4

We currently have a windows 2.8 moodle server and we need to change the hostname and IP address of the server to a new domain.  So the hostname is currently server.domain.com and it needs to be changed to newserver.newdomain.com.  How do I go about doing this? 


Thanks in advance

Tim


Average of ratings: -
In reply to Tim Huff

Re: Changing name and IP of moodle server

by Bret Miller -
Picture of Particularly helpful Moodlers

I assume you're asking about what you need to do in Moodle. Just a couple of things:

  1. Change $CFG->wwwroot in your config.php to the new URL.
  2. Run the search/replace tool (login in as an admin, tack /admin/tool/replace/index.php onto the root url) to replace the old URL with the new URL.
In reply to Bret Miller

Re: Changing name and IP of moodle server

by Tim Huff -
I am a little confused regarding number 2. Can you clarify? Also do I need to do anything in apache?
In reply to Tim Huff

Re: Changing name and IP of moodle server

by Bret Miller -
Picture of Particularly helpful Moodlers

The search/replace tool is a hidden admin tool in Moodle. It essentially allows you to search for a string in the database and replace it with another. It comes with serious warnings that you can mess up the website so bad that it will no longer work. Taking a full backup of the database should be considered a requirement before running search/replace. However, it is the only tool that will successfully change a URL in the database if any are present in blocks. To use the replace tool:

  1. Log into your Moodle site as an administrator
  2. Add /admin/tool/replace/index.php to your Moodle URL. So, if you Moodle URL is http://example.com, then the replace tool is at http://example.com/admin/tool/replace/index.php.
  3. Fill in the "search whole database for" box with the old URL
  4. Fill in the "replace with this string" box with the new URL
  5. Check the box for "shorten result if necessary". It appears to be required, at least the last time I used the tool.
  6. Check the box for "I understand the risks of this operation".
  7. Click the "Yes do it!" button.
Average of ratings: Useful (3)
In reply to Tim Huff

Re: Changing name and IP of moodle server

by Jez H -

Yes you will need to update apache to point newdomain.com at your Moodle install directory.

You then need to update Moodle config to tell Moodle iteself it is now on newdomain.com

The other thing you need to do is replace all references in the database changing olddomain.com to new domain.com

Let us say for example a teacher hard coded a link in a label linking to another page or file in Moodle, or made a forum post that said "please enroll on this course [click here link]", those links all need to be updated and there are dozens of places they can appear, forum posts, labels, pages... anywhere the text editor allows you to drop a link in Moodle could potentially have hard coded (manually added by users) links.

That is why Bret has recommended using the string replace tool in Moodle.

There is another way to do this which is to dump the database to a text file and do the string replace on the file system then re-import the file.

One thing you need to be mindful of is that if muchlongernewdomain.com is longer than olddomain.com, that is the new domain has more characters in it you can run into problems with serialized data in html blocks and any other fields which track character length. I have never used the string replace tool Bret mentions but would hope (given it is a Moodle built tool) it handles issues around serialization of blocks where the serialized data contains the number of characters and throws errors if actual characters are different to the expected values).



Average of ratings: Useful (1)