Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active August 16, 2022 06:28
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • 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:

@jlam55555
Copy link

@calebfergie I haven't tried this (MediaWiki on Heroku) but I do know that Heroku has an ephemeral filesystem. I'm not sure how to do it with MediaWiki, but I believe the norm is to host files other platform, e.g., S3.

@calebfergie
Copy link

calebfergie commented Aug 19, 2019

@jlam55555 yep, you're right -to work around this I ended up using an S3 bucket to store the images with the AWS Extension

You can see the full setup here.

@lwisparra
Copy link

lwisparra commented Oct 21, 2019

Hello! I followed all the steps, but going to wikiname.herokuapp.com returns a blank screen :( I think it can be because the installation of the skin failed: I added both "mediawiki/vector-skin": "dev-wmf/1.30.0-wmf.2", and wfLoadSkin( 'Vector' ); in composer and LocalSettings, and the Vector folder in the skins directory, but when updating composer it didn't work. What could I have done wrong? Thank you :)

@calebfergie
Copy link

@luisparradev I had a similar issue - not sure if it will work for your setup, but you can try what I did above: https://gist.github.com/caseywatts/d04bda6626ef2c6c8f97#gistcomment-2862896

@xahon
Copy link

xahon commented Dec 9, 2019

Is there a one-click deploy?

@ApopheniaPays
Copy link

Ok. Much as I appreciate the effort to help, the long and winding set of directions, followed by subsequent corrections and additions to those directions, and concluding with someone saying "All I get is a blank screen" and no decisive answer, then someone asking "Is there a one-click deploy" and no answer, does not look like a good use of time. However, I'm commenting to subscribe, in the hopes that someday somebody updates this with concise, confirmed working instructions.

@WAUthethird
Copy link

Please update this guide - brew installs Composer 2 by default which is incompatible with MediaWiki:
https://www.mediawiki.org/wiki/Composer

@WAUthethird
Copy link

PSA: I DO NOT RECOMMEND USING CLEARDB WITH MEDIAWIKI

Pages load so incredibly slow, and normal usage can result in the entire database crashing.
Switching to Amazon Aurora. This was horrible.

@reneklacan
Copy link

I ran into following issue while trying to follow instructions and deploying to heroku:

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote:  !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote: 			Detected buildpacks: PHP,Node.js
remote: 			See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:
remote:  !     ERROR: Failed to install system packages!
remote:  !
remote:  !     Your platform requirements (for runtimes and extensions) could
remote:  !     not be resolved to an installable set of dependencies, or a
remote:  !     platform package repository was unreachable.
remote:  !
remote:  !     This usually means that you (or packages you are using) depend
remote:  !     on a combination of PHP versions and/or extensions that are
remote:  !     currently not available on Heroku.
remote:  !
remote:  !     The following is the full output from the installation attempt:
remote:  !
remote:  !     > You are using Composer 1 which is deprecated. You should upgrade to Composer 2, see https://blog.packagist.com/deprecating-composer-1-support/
remote:  !     > Loading repositories with available runtimes and extensions
remote:  !     > Updating dependencies
remote:  !     > Your requirements could not be resolved to an installable set of packages.
remote:  !     >
remote:  !     >   Problem 1
remote:  !     >     - The requested package composer-plugin-api could not be found in any version, there may be a typo in the package name.
remote:  !     >
remote:  !
remote:  !     For reference, the following runtimes are currently available:
remote:  !
remote:  !     PHP:  8.1.1, 8.1.0, 8.0.14, 8.0.13, 8.0.12, 8.0.11, 8.0.10,
remote:  !     8.0.9, 8.0.8, 8.0.7, 8.0.6, 8.0.3, 8.0.2, 8.0.1, 8.0.0,
remote:  !     8.0.0RC4, 7.4.27, 7.4.26, 7.4.25, 7.4.24, 7.4.23, 7.4.22,
remote:  !     7.4.21, 7.4.20, 7.4.19, 7.4.16, 7.4.15, 7.4.14, 7.4.13,
remote:  !     7.4.12, 7.3.33, 7.3.32, 7.3.31, 7.3.30, 7.3.29, 7.3.28,
remote:  !     7.3.27, 7.3.26, 7.3.25, 7.3.24
remote:  !
remote:  !     Please verify that all requirements for runtime versions in
remote:  !     'composer.lock' are compatible with the list above, and ensure
remote:  !     all required extensions are available for the desired runtimes.
remote:  !
remote:  !     When choosing a PHP runtimes and extensions, please also ensure
remote:  !     they are available on your app's stack (heroku-20), and select
remote:  !     a different stack if needed after consulting the article below.
remote:  !
remote:  !     For a list of supported runtimes & extensions on Heroku, please
remote:  !     refer to: https://devcenter.heroku.com/articles/php-support
remote:
remote:  !     Push rejected, failed to compile PHP app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !	Push rejected to aoe4world-mediawiki.
remote:

It looks like issue might be that Heroku is trying to use composer 1 even though 2 should be supporter and it's failing, I only spent ~20 mins on trying to solve it with no success.

@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