Monday, June 23, 2014

Moodle - Change a moodle site's domain name

To change your moodle site's domain name, for example from "old.domain.com" to "new.domain.com" you have to do following things:

0. Point new.domain.com to your moodle site's IP address

1. Go to the replace admin tool in your moodle (still running at the old.domain.com) and replace http://old.domain.com with http://new.domain.com in every record that has the url:

http://old.domain.com/admin/tool/replace/
( version >= 2.5)





2. Open /moodle/root/path/config.php and change the wwwroot to the new domain:

$CFG->wwwroot   = 'http://new.domain.com';


3. Change your nginx / apache configuration to retrieve server name as the new.domain.com (I use nginx ):

...

server_name new.domain.com;
...


4. Restart nginx and php5-fpm:

$ sudo service nginx restart
$ sudo service php5-fpm restart


5. In addition, you can also clean the cache of your moodle:

$ sudo rm -rf /moodle/data/path/cache/cachestore_file/default_application/core_databasemeta/*
$ sudo rm -rf /moodle/data/path/cache/cachestore_file/default_application/core_config/*


Now you can access your moodle site with the new domain name.