Change the URL of a Chamilo portal copy

There is a surprising number of cases where you'd want to change the URL of a Chamilo portal, but the more common we see is when you take a backup copy of a portal and want to use that copy to build a new test portal. Obviously, if you keep the same URL, you're going to have difficulties having them both running at the same time. Chamilo is not good at managing several URLs (although another article on this blog will help you do that), and even less good at managing a dynamic URL, so there are 3 necessary steps to change the URL (this is valid at least until version 1.11 of Chamilo).

Step 1: Update configuration.php

Whether main/inc/conf/configuration for version 1.9 and below, or app/config/configuration.php for version 1.10 and above, you'll have to edit the file, locate the $_configuration['root_web'] = '...'; line and update the value to the new URL. Once you've done that, Chamilo will understand it has to answer to another name. If you're on the same server in another folder, think about changing $_configuration['root_sys'] as well.

Step 2: Update HTML files in the courses/ directory

This is not the only place where some hardcoded links might be present in HTML files, but fixing this directory will certainly fix more than 50% of the issues. The directory is /courses/ in 1.9 and below, and /app/courses/ in 1.10 and above. Go into the directory and then launch:

find . -type f -exec sed -i 's/' {} \;

Where is the previous URL, and is the new URL. This will effectively replace (if you have the permissions to edit the files) all HTML files that might have contained a hardcoded link to the previous URL.

Step 3: Update Apache config

Whether you use Apache or Nginx or any other webserver, you'll have to update the virtual host config you have (actually, the copy you made of the original portal's virtual host), to replace URL1 by URL2. Just edit the virtual host config file (usually somewhere like /etc/apache2/sites-available/ or /etc/httpd/ or /etc/nginx/sites-available/) and don't forget to reload the config afterwards. This should get your duplicated Chamilo portal up and running!