Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active August 16, 2022 06:28
Show Gist options
  • Save caseywatts/d04bda6626ef2c6c8f97 to your computer and use it in GitHub Desktop.
Save caseywatts/d04bda6626ef2c6c8f97 to your computer and use it in GitHub Desktop.
Mediawiki on Heroku

Short url: caseywatts.com/mediawikionheroku

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

How to get set up with Mediawiki running on Heroku.

Create Git Repo

Fork https://github.com/mediawiki/mediawiki (from the web interface)

(master worked fine for me, but you might want the last stable tag?)

git clone https://github.com/YOURUSERNAME/mediawiki
heroku apps:create YOURAPPNAME

composer.lock setup

Mediawiki's repo doesn't have a composer.lock in it, and Heroku requires one. (I wish I knew more about why they didn't check that in?)

Before being able to generate a composer.lock, you may need to get php installed using brew see here (brew is for OSX). Packagist require you use a not-old version of openssl in your php, or else it won't let you download packages from it. Installing through brew gets a newer version of openssl bundled into your install of php.

Generate and add to the repo a composer.lock

brew install composer
composer update
git add -f composer.lock
git commit -m "add composer.lock"
git push heroku master

Configuring with ClearDB

Install an instance of ClearDB, either through the Heroku Dashboard or CLI. The free database isn't enough, you'll probably need the cheapest paid one ('punch', not 'ignite').

heroku addons:create cleardb:punch

Get the database information from the CLEARDB_DATABASE_URL ready to use soon mysql://USERNAME:PASSWORD@HOST/TABLENAME (and there is no table prefix)

heroku config

Now go to your deployed Heroku app, and follow the setup wizard. Put in the database information where requested.

Once you're done, you'll have to download LocalSettings.php and change some things before checking it into the repo. DO NOT check in LocalSettings.php with the passwords still in it. Instead, we'll use ENV vars.

LocalSettings.php

Replace the ## Database settings sesction of LocalSettings.php with this (based on this):

## Database settings
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));

$wgDBtype = "mysql";
$wgDBserver = $url["host"];
$wgDBname = substr($url["path"], 1);
$wgDBuser = $url["user"];
$wgDBpassword = $url["pass"];

Move the $wgSecretKey into an ENV var:

$wgSecretKey = getenv("SECRET_KEY");

Also move the $wgUpgradeKey into an ENV var:

$wgUpgradeKey = getenv("UPGRADE_KEY");

Now you can add, check in, push the new file "LocalSettings.php"

git add -f "LocalSettings.php"
git commit -m "add LocalSettings.php"
git push heroku master

Installing a Skin (Vector)

You can install the vector skin by adding it to the composer.json - add a line something like this (followed by composer update):

"mediawiki/vector-skin": "dev-wmf/1.30.0-wmf.2",

Then you'll have to add the skin explicitly to the bottom of LocalSettings.php like the instructions on the deployed site say to do (but what is the default skin for if it's not used??):

wfLoadSkin( 'Vector' );

Related: https://www.mediawiki.org/wiki/Download_from_Git#Using_Git_to_download_MediaWiki_skins

An Example Setup

https://github.com/caseywatts/yalewiki

Compare it to mediawiki's repo to see the differences: https://github.com/wikimedia/mediawiki/compare/master...caseywatts:master

Credits

Inspiration taken from:

@klaraseitz
Copy link

To anyone still struggling:
I have written an updated tutorial on setting up mediaWiki on Heroku here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment