Place MediaWiki inside a Virtual Host

From SaruWiki
Revision as of 18:40, 31 January 2009 by Saruman! (talk | contribs) (→‎The solution: added SSL note)
Jump to navigation Jump to search

The problem

The Debian installation of MediaWiki is quite simple, and immediately after installation you can visit http://www.example.com/wiki, and find your new wiki ready for you. However, if you start using VirtualHosts, and create a second site www.alsoexample.com, then a visit to http://www.alsoexample.com/wiki will reveal the same wiki instance. In fact, whatever virtual host you deploy, on the URI path /wiki you'll always find your single wiki instance deployed.

This might be what you want, but usually it is not. Reason for that would of course be that you customize your wiki to show your www.example.com address in the title bar, or that all subject matter is about "example", and not about "alsoexample".

The cause

So the URI /wiki is pointing to your wiki for every VirtualHost you deploy. The reason that your wiki is behaving like this, is that the Debian installation has created a symlink /etc/apache2/conf.d/mediawiki that's pointing to /etc/mediawiki/apache.conf. The contents of the conf.d directory are included in the Apache configuration, so the MediaWiki configuation is nicely read and understood. However, the apache.conf configuration file is not VirtualHost compatible; it just aliases the web folder /wiki to the /var/lib/mediawiki directory, without regards for the virtual host name that's called upon. In fact, the first few lines of apache.conf admit as much:

# Uncomment this to add an alias.
# This does not work properly with virtual hosts..
Alias /wiki /var/lib/mediawiki

The solution

First make sure the MediaWiki configuration is not loaded by Apache2 outside of the VirtualHost settings

unlink /etc/apache2/conf.d/mediawiki.conf

Next, open the site-configuration for the site that should keep the MediaWiki setting, e.g. /etc/apache2/sites-available/000-saruman.biz. In this configuration, paste the relevant information as it exists in /etc/mediawiki/apache.conf, e.g.

       Alias /wiki /var/lib/mediawiki

        <Directory /var/lib/mediawiki/>
                Options +FollowSymLinks
                AllowOverride All
                order allow,deny
                allow from all
        </Directory>

        # some directories must be protected
        <Directory /var/lib/mediawiki/config>
                Options -FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/lib/mediawiki/upload>
                Options -FollowSymLinks
                AllowOverride None
        </Directory>

Finally, restart Apache2:

invoke-rc.d apache2 restart

This should ensure that the /wiki path stays active under your main/intended site, and not under your other sites.

Note: if you need this solution under the SSL variant of the site as well, repeat this for the relevant config file, e.g. 000-saruman-ssl.biz.