Place MediaWiki inside a Virtual Host: Difference between revisions

From SaruWiki
Jump to navigation Jump to search
m (changed wikisettings from paste-job to include)
m (added example VirtualHost config)
 
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 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:
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 somewhere within the <VirtualHost> declaration:
  Include /etc/mediawiki/apache.conf
  Include /etc/mediawiki/apache.conf
Then restart Apache2:
This means that, if you've not done any customization yet on your Apache2 installation, the site declaration ''/etc/apache2/sites-available/default'' could look something like this:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
        Include /etc/mediawiki/apache.conf
        ErrorLog /var/log/apache2/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>
To effectuate the change, 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 any of 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''.

Latest revision as of 20:51, 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 somewhere within the <VirtualHost> declaration:

Include /etc/mediawiki/apache.conf

This means that, if you've not done any customization yet on your Apache2 installation, the site declaration /etc/apache2/sites-available/default could look something like this:

<VirtualHost *:80>
       ServerAdmin webmaster@localhost

       DocumentRoot /var/www/
       <Directory />
               Options FollowSymLinks
               AllowOverride None
       </Directory>
       <Directory /var/www/>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride None
               Order allow,deny
               allow from all
       </Directory>

       ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
       <Directory "/usr/lib/cgi-bin">
               AllowOverride None
               Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
               Order allow,deny
               Allow from all
       </Directory>

       Include /etc/mediawiki/apache.conf

       ErrorLog /var/log/apache2/error.log

       # Possible values include: debug, info, notice, warn, error, crit,
       # alert, emerg.
       LogLevel warn

       CustomLog /var/log/apache2/access.log combined

   Alias /doc/ "/usr/share/doc/"
   <Directory "/usr/share/doc/">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 127.0.0.0/255.0.0.0 ::1/128
   </Directory>

</VirtualHost>

To effectuate the change, 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.