If you need to move your Moodle site to a new domain or make it accessible from a different URL, you must update its configuration settings. The key step is modifying the config.php file in Moodle’s main directory.
Step 1: Locate the config.php File
The config.php file is located in the root folder of your Moodle installation. You can access it via FTP, your hosting file manager, or SSH, depending on your setup.
Step 2: Edit the wwwroot Setting
Open config.php with a text editor. Look for the line that defines the site’s URL, which looks like this:
$CFG->wwwroot = 'http://olddomain.com';
Replace the old domain with your new domain name. For example:
$CFG->wwwroot = 'http://newdomain.com';
Make sure to use the correct protocol (http or https) based on your SSL setup.
Step 3: Save Changes and Clear Cache
After updating the URL, save the file and upload it back to the server if you edited it locally. Then, clear your browser cache to ensure Moodle loads from the new domain without issues.
Step 4: Verify the Site
Visit your new domain in a browser and check that your Moodle site loads correctly. Test a few pages and login to confirm all internal links now point to the new domain.
Important Notes:
- If your Moodle site uses additional plugins or external integrations, make sure they also reference the new domain.
- Back up your config.php file before making changes to avoid accidental misconfigurations.
By updating the $CFG->wwwroot value, your Moodle site will now function properly under the new domain, ensuring a smooth transition for your users.
Experience fast, secure, and reliable Moodle hosting with TrexHost—launch your site today and enjoy worry-free performance.