Place MediaWiki inside a Virtual Host: Difference between revisions

From SaruWiki
Jump to navigation Jump to search
m (→‎The solution: added SSL note)
m (changed wikisettings from paste-job to include)
Line 13: Line 13:
First make sure the MediaWiki configuration is not loaded by Apache2 outside of the VirtualHost settings
First make sure the MediaWiki configuration is not loaded by Apache2 outside of the VirtualHost settings
  unlink /etc/apache2/conf.d/mediawiki.conf
  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.
Next, open the site-configuration for the site that should receive the MediaWiki setting, e.g. ''/etc/apache2/sites-available/000-saruman.biz''. In this configuration, include the mediawiki setting, by inserting the following line:
        Alias /wiki /var/lib/mediawiki
Include /etc/mediawiki/apache.conf
Then restart Apache2:
        <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
  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.
This should ensure that the ''/wiki'' path stays active under your main/intended site, and ''not'' under any of 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''.
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''.

Revision as of 20:47, 3 February 2009

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 receive the MediaWiki setting, e.g. /etc/apache2/sites-available/000-saruman.biz. In this configuration, include the mediawiki setting, by inserting the following line:

Include /etc/mediawiki/apache.conf

Then restart Apache2:

invoke-rc.d apache2 restart

This should ensure that the /wiki path stays active under your main/intended site, and not under any of 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.