Changing the URL of a Moodle instance later

Changing the URL of a Moodle instance later

by Visvanath Ratnaweera -
Number of replies: 8
Picture of Particularly helpful Moodlers Picture of Translators
Since the URL of a Moodle instance is stored in its configuration, if you happen to "move" an installation, say from http://mydomain/testmoodle/ to http://moodle.mydomain, needs a few tweaks.

What is the neat way of handling that?

The server is Linux with full (user and root) shell access.
Average of ratings: -
In reply to Visvanath Ratnaweera

Re: Changing the URL of a Moodle instance later

by J B -
The site URL is set in the file /testmoodle/config.php as wwwroot.

Open config.php in a text editor, there will be a line:

    $CFG->wwwroot   = 'http://mydomain/testmoodle';

Change this to read:

    $CFG->wwwroot   = 'http://moodle.mydomain';
Job done.

In reply to J B

Re: Changing the URL of a Moodle instance later

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
That one is too good to be true!

Are you sure, for example, this URL is not stored in the database?
In reply to Visvanath Ratnaweera

Re: Changing the URL of a Moodle instance later

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No it isn't stored in the database - UNLESS someone has placed a self-referring link somewhere in a resource.

It's kinda the point of the config file - vital information in one place tongueout
In reply to Howard Miller

Re: Changing the URL of a Moodle instance later

by J B -
As Howard says.

It helps if your test moodle is in its own subdomain, e.g. test.mydomain.com so you can then structure relative links in the form

<a href="/course/view.php?id=5"> click here! </a>

then when you move the site to live.mydomain.com all the links will work.

In reply to J B

Re: Changing the URL of a Moodle instance later

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi James

> It helps if your test moodle is in its own subdomain, e.g. test.mydomain.com so you can then structure relative links ...

Yes. I have it like http://moodle.mydomain for the production, http://moodle.mydomain/testmoodle/ for the test-run.

I really don't have control over what sort of URL links the course creators set. Will do a SQL dump and check.

Thanks for all the responses!

Visvanath


In reply to Visvanath Ratnaweera

Re: Changing the URL of a Moodle instance later

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The only other thing you should watch out for is if you (or anybody else) has used self-referring links anywhere in resource texts. If that is the case and you have a manageable number of courses you may be better to use backup and restore which takes care of that kind of stuff.
In reply to Howard Miller

Re: Changing the URL of a Moodle instance later

by Rory Allford -
Does anyone know whether an SQL regex UPDATE is possible (in MySQL), and if so could it be used to change all the stored values of $CFG->wwwroot ? It'd be a nice trick to save doing a full site-wide backup/restore to correct the values.
In reply to Rory Allford

Re: Changing the URL of a Moodle instance later

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
That was my suspicion too. I expected a full database dump, a run through sed and a restore.

But all the Gurus say that is not necessary, "unless there are self-referencing links in content".