Changing your website domain is a big step—but if you’re running Moodle, there are a few extra steps you must take to ensure everything continues working smoothly.
If you’re hosting your site with KamHost, or planning to, this process can be much easier thanks to optimized environments, control panel tools, and expert support. You can also explore our Moodle hosting solutions to simplify setup, performance, and ongoing management.
Why Updating Moodle’s Domain Is Important
When you switch domains, Moodle still “thinks” your site is using the old URL. This can cause:
- Users being redirected to the old domain
- Images and files not loading
- SSL or mixed content warnings
- Login/session issues
👉 With KamHost’s Moodle hosting, many of these issues are easier to manage with pre-configured environments and built-in tools.
Step 1: Update Your Domain in the Hosting Control Panel
Before making any changes to Moodle itself, you need to ensure that your server is properly configured to respond to the new domain. In most cases, this can be done directly through your hosting control panel—no manual server configuration is required.
In your hosting control panel, navigate to My Domains → Hosted Domains, then add your new domain name. During this process, open the Advanced Settings and set the Path (document root) to your existing Moodle installation directory. This ensures that the new domain points to the same website files as your current Moodle site.
💡 Tip: With KamHost, this process only takes a few clicks and does not require technical server knowledge.
If you are using a VPS or dedicated server without a hosting control panel, you will need to manually configure your web server to recognize the new domain.
For Apache servers:
Create or edit a virtual host file:
<VirtualHost *:80>
ServerName new-domain.com
ServerAlias www.new-domain.com
DocumentRoot /var/www/moodle
<Directory /var/www/moodle>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Then enable the site and reload Apache:
sudo a2ensite new-domain.conf
sudo systemctl reload apache2
For Nginx servers:
Create or edit a server block:
server {
listen 80;
server_name new-domain.com www.new-domain.com;
root /var/www/moodle;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
}
Then reload Nginx:
sudo systemctl reload nginx
💡 Important:
Make sure the DocumentRoot (Apache) or root (Nginx) points to your existing Moodle installation directory. Otherwise, the new domain will not load your site correctly.
Step 2: Update the Moodle config.php File
Next, update your site URL inside Moodle.
📍 Locate:
/path-to-your-moodle/config.php
Find:
$CFG->wwwroot = 'https://old-domain.com';
Update to:
$CFG->wwwroot = 'https://new-domain.com';
✅ Tips:
- Use https:// if SSL is enabled
- No trailing slash
👉 If you’re using KamHost, you can edit this file easily via File Manager or SSH.
Step 3: Replace Old Domain URLs in the Database
Moodle stores links in the database, so this step is essential.
Recommended Method (CLI)
php admin/cli/replace.php --search=old-domain.com --replace=new-domain.com
👉 On KamHost VPS or cloud hosting, SSH access is enabled for quick execution.
Alternative Method (phpMyAdmin)
- Open phpMyAdmin
- Select your database
- Run:
UPDATE mdl_config SET value = REPLACE(value, 'old-domain.com', 'new-domain.com');
⚠️ Replace mdl_ with your table prefix.
Step 4: Clear Moodle Cache
Apply changes by clearing cache.
Using CLI:
php admin/cli/purge_caches.php
Or manually:
- Clear
/moodledata/cache/ - Clear
/moodledata/localcache/
👉 With KamHost, cache directories are easily accessible and optimized.
Step 5: Install SSL for the New Domain
Secure your new domain with SSL. A popular free option is Let’s Encrypt.
👉 All KamHost Moodle hosting plans include free SSL for quick activation.
Step 6: Test Your Website
After completing the updates, test thoroughly:
- Login functionality
- Images and files
- Internal links
- Redirect behavior
Step 7: Redirect Your Old Domain (Recommended)
Set up a 301 redirect to preserve SEO and user traffic.
👉 With KamHost, redirects can be configured easily via control panel or .htaccess.
Common Issues and Fixes
Redirect Loop
→ Check $CFG->wwwroot
Broken Links or Images
→ Database replacement incomplete
Mixed Content Warnings
→ Some URLs still using HTTP
Important: Control Panel vs Moodle Configuration
Many users assume changing the domain in the control panel is enough—but it’s not.
👉 Here’s the difference:
- Control Panel → Connects domain to your server
- Moodle Configuration → Updates internal URLs
✅ You must do both steps for everything to work correctly.
Ready to Simplify Moodle Hosting?
Managing Moodle manually can be time-consuming—especially when dealing with domain changes, databases, and server configurations.
With KamHost’s Moodle Hosting, you get:
- Optimized servers for Moodle performance
- Easy domain and SSL management
- Control panel + SSH access
- Expert support when you need it
👉 Explore KamHost Moodle Hosting today and make managing your LMS faster, easier, and more reliable.
