Mediawiki farm on subdomains

March 13, 2019 292 views
Configuration Management Ubuntu 18.04

Hey!

I’m currently running Mediawiki in my standard Apache folder, that is, /var/www/html.
I’ve now been tasked to make the Mediawiki multilingual, which I can achieve by creating a wiki farm through setting up technically individual wikis on different subdomains through virtual hosts and then connecting them through Mediawiki extensions.

I’ve tried experimenting with the virtual hosts recently, though I only got it to work to a degree.

So, before crashing stuff, I just wanted to ask you about my concrete problem:

I want to move the current installation of Mediawiki located at /var/www/html/ to /var/www/html/de/, as well as copy that same installation to /var/www/html/en/ (for later editing, just to not have to reinstall it again).

And, subsequently, I want de.example.com to point at /var/www/html/de/ and en.example.com at /var/www/html/en/.

Additionally, example.com should link to de.example.com

Since I’m currently kind of confused at how to properly achieve this, I’d really appreciate just a quick concrete guide for this specific problem.

Thank you in advance!

1 Answer

Greetings!

You are on the right path for this. You can use Apache virtual hosts to handle the multiple subdomains. Your folder structure is also attractive, it doesn’t make a common mistake (nesting one install under another). Copying the files from one folder to another should be fine too, something like:

cp -R /var/www/html/de /var/www/html/en

Here’s a guide on Apache virtual hosts:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04

The next thing you want to take care of is the database. MediaWiki supports MySQL, PostgreSQL, and SQLite. If you run SQLite this is stupid easy, and I’m jealous of how easy it is for you. At that point it’s just done, you need go no further. Kick back and relax. Unfortunately, or fortunately if you dislike SQLite, that probably isn’t how you have it setup.

I’m going to take a shot in the dark and assume you’re running MySQL for it. Look for your LocalSettings.php file and grab your MySQL configuration variables. Here is some information on that: https://www.mediawiki.org/wiki/Manual:Configuration_settings#MySQL-specific

Here’s an example of what those might look like:

$wgDBtype           = "mysql";
$wgDBserver         = "localhost";
$wgDBname           = "my_wiki";
$wgDBuser           = "root";
$wgDBpassword       = "1234";

For my purpose, I’m going to assume the example above to be accurate. So any time you see me mention those values below, know that you need to replace them with your own. I’m also going to adjust them for the new wiki, and that is going to be these variables, which you will also change as desired:

$wgDBtype           = "mysql";
$wgDBserver         = "localhost";
$wgDBname           = "my_wiki_en";
$wgDBuser           = "wiki_en";
$wgDBpassword       = "1234";

I’m going to copy the database:

mysqldump my_wiki > /root/my_wiki.db

mysql
create database my_wiki_en;
grant all on my_wiki_en.* to wiki_en identified by '1234';
quit;

mysql my_wiki_en < /root/my_wiki.db

Then I would edit LocalSettings.php on the EN installation to match the ones I mentioned above:

$wgDBtype           = "mysql";
$wgDBserver         = "localhost";
$wgDBname           = "my_wiki_en";
$wgDBuser           = "wiki_en";
$wgDBpassword       = "1234";

Now the EN version of the wiki should be set. It should go without saying, but don’t be like me and use 1234 as a password :)

Jarland

by Brennen Bearnes
The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 16.04 server.
Have another answer? Share your knowledge.