Setup Virtual Hosts for Mahara and Moodle

The Webserver Apache gives you the Opportunity to setup virtual namebased Hosts for different Projects. If you are working on different projects in your localhost-section, virtual Hosts can help you to organize different projectdata-paths on one IP-Address. Because we also wanted to have the possibility to perhaps install different versions of moodle, we setup a virtual host for both moodle and mahara.

 

To configure a vHost in Apache2 on a Ubuntu 12.04 System, we only had to insert a new configuration file for each projectfolder inside the folder /etc/apache2/sites-available/ with the following content:

 

The file badgesproject_moodle.conf

<VirtualHost *:80>
ServerName moodle.badges-project.local
DocumentRoot /var/www/BadgesProject/moodle/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/BadgesProject/moodle/>
Options -Indexes +FollowSymLinks -MultiViews -Includes
AllowOverride All
AcceptPathInfo On
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error-badges.log
CustomLog /var/log/apache2/access-badges.log combined
</VirtualHost>

 

The file badgesproject_mahara.conf

<VirtualHost *:80>
ServerName mahara.badges-project.local
DocumentRoot /var/www/BadgesProject/mahara/htdocs/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/BadgesProject/mahara/htdocs/>
Options +Indexes +FollowSymLinks +MultiViews +Includes
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error-badges-mahara.log
CustomLog /var/log/apache2/access-badges-mahara.log combined
</VirtualHost>

 

You also define the path to the errorlogs inside of this, so if you are running into problems you can look up these files.

 

To activate or disable the sites on Apache two administrator commands are available:

 

activate: a2ensite etc/apache2/sites-available/badgesproject_moodle.conf
disable: a2dissite etc/apache2/sites-available/badgesproject_moodle.conf
always restart apache after this: /etc/init.d/apache2 restart

 

You can see the enabled sites in the folder: etc/apache2/sites-enabled/.

 

If you are using the Softwarebundle XAMPP, the configuration files of Apache Server are divided in importable files and you have to uncomment the import of the file httpd-vhosts.conf inside of the main configuration file httpd.conf. You have to define the vHost Configuration content inside of the file httpd-vhosts.conf.

 

For making the virtual adresses available, you have to configure the hosts file (e.g Linux: /etc/hosts) of your operating system by adding these lines:

 

::1 moodle.badges-project.local
fe80::1%lo0 moodle.badges-project.local
127.0.0.1 moodle.badges-project.local
::1 mahara.badges-project.local
fe80::1%lo0 mahara.badges-project.local
127.0.0.1 mahara.badges-project.local

 

Thats all!