Setting Up MediaWiki on an Apple Mac

After one too many issues with a Hackintosh and a short but painful trip to an Apple store my MediaWiki Windows installation needed moving across into the unknown realms of OSX. After some surprising turns the install worked and the steps have been captured for posterity.

What Do I Need To Try This Out

The post is split into two sections, the first covers a basic MediaWiki installation and the second covers setting up MediaWiki Math support.
For a basic installation:

  1. MediaWiki. I’m using 1.20.0 which can be picked up here
  2. XCode and the Command Line Tools for XCode. DL XCode from the Apple App Store, you’ll need to pick up the Command Line Tools for XCode from here;
  3. Libltdl. You can pick this up from here;
  4. Imagemagick. Use 6.7.2, which you can pick up from here; I don’t want to use MacPorts, so I couldn’t use the built version on
  5. Mamp. The installation works with 2.1.1 which can be picked up from here;

For MediaWiki Math support:

  1. MediaWiki Math Extension. Download the 1.19 version;
  2. Ocaml. Download the 4.01 version;
  3. LaTex. Download the 2.1G version;
  4. Ghostscript. Download the 9.06 version;

How To… Install The Basic Verson

  • Download and install XCode and the Command Line Tools for XCode from the App Store. There should be nothing much to this step…
  • Download and install libltdl. Make sure that it isn’t the MacPort version. You’ll need to carry this out from the command line:
    • tar -xvf <libltdl tarball filename>
    • ./configure
    • make all
    • sudo make install
  • Download and install the non-MacPort version of ImageMagick. I did this from inside the /tmp area, however you can do this from any temp folder. Run the following from a command line:
    • cd /tmp
    • curl -OL
    • tar -xzf ImageMagick.tar.gz
    • cd ImageMagick-6.7.2-7/
    • ./configure –prefix=/usr/local –disable-static –with-modules –without-perl –without-magick-plus-plus –with-quantum-depth=8 –disable-openmp –with-gs-font-dir=/usr/local/share/ghostscript/fonts
    • make
    • sudo make install
  • Install MAMP, which has a nice wizard for you to work through. Some things to check:
    • There were some oddities with Mamp PRO that I didn’t want to take the time to sort out, so only got basic Mamp running.
    • Change the installation directory to someplace logical, like Applications > Mamp.
    • Create a folder under Users/<username>/Sites and change the Apache directory to point to that.
  • Installing MediaWiki. There are a few things that will need to be done before you start the MediaWiki installation process:

    • Untar the MediaWiki tarball to Users/<username>/Sites and change the foldername to mediawiki.
    • Turn off arbitrary scripting in the images upload directory, you’ll need to add some code to the httpd.conf file under Applications/MAMP/conf/apache/httpd.conf. Add the following to the script:

      # Turned off arbitrary scripting to the wiki upload directory.
      <Directory "/Users/<USERNAME>/Sites/mediawiki/images">
      # Ignore .htaccess files
      AllowOverride None

      # Serve HTML as plaintext, don't execute SHTML
      AddType text/plain .html .htm .shtml .php

      # Don't run arbitrary PHP code.
      php_admin_flag engine off

      # If you've other scripting languages, disable them too.

    • Restart the Apache server.
    • Start the MediaWiki installation:
      • Change the database password to something useful.
      • Create a Wiki user, ZomboidRelic9 for example.
      • Create a sensible password for your user.
      • Once the process is complete, copy LocalSettings.php from its folder to the MediaWiki root.

…And that should be about it. You should now be able to create pages like this:

How To… Install the MediaWiki Math Extension

This is really handy if you’re looking to embed math notation like this… …into your wiki posts.

  • Install Ocaml. This should be relatively straightforward once you DL and run the binary DMG.
  • Install LaTex. Again this should be relatively straightforward once you DL the PKG. Make a note where it has been installed to, it should be something like
  • Install Ghostscript. This comes down as a tar ball, untar this somewhere helpful and from the command line.
    • ./configure
    • sudo make intall
  • Installing the Math extension. Unfortunately it looks like there are quite a few things you’ll need to do to get this working:
    • Download the tarball
    • Untar it to your mediawiki extension directory
      tar -xzf Math-MW1.19-xxxxx.tar -C /Users/<username>/Sites/mediawiki/extensions
    • Add the following to your LocalSettings.php file:
    • Run the mediawiki update script from a command line.
      php /Users/<Username>/Sites/mediawiki/maintenance/update.php
    • Create a socket connection. Again from the command line:
      • cd /var
      • sudo mkdir mysql
      • sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
    • Build texvc:
      • Set the paths for latex/dvips etc… look in in the /Users/<username>/Sites/mediawiki/extensions/Math/Math folder. At the top of the file, hardcode the paths to where the applications exist in your system. Then from the command line:
        • cd /Users/<username>/Sites/mediawiki/extensions/Math/math
        • sudo make all
      • Add a path to texvc in LocalSettings.php. It should look something like:

        # Path to texvc
        $wgTexvc = "/Users/<username>/Sites/mediawiki/extensions/Math/math/texvc";
    • Look in the LocalSettings.php file and uncomment the line “$wgHashedUploadDirectory = false;”. You’ll need to create the required archive/thumb and temp directories as the attached comment suggests.
  • Add some test Math xml to your root wiki page.
  • Your wiki will be cached, so to reload your root MediaWiki page, add “?action=purge” to the end of the URL to force it to take account of the changes you’ve been making.

Unfortunately here is where you may start to have problems. MAMP changes the DYLD_LIBRARY_PATH to use the Macport version for some of the paths and you should be using the Apache libs which are built with OSX. If you look in the console you will probably have a set of dvipng and convert with Symbol not found: _cg_jpeg_resync_to_restart etc errors. If you’re interested in tracking down the errors yourself, you can turn on the debugging and logging by adding the following to the top of your LocalSettings.php file and clearing the wiki cache:

error_reporting( -1 );
ini_set( 'display_errors', 1 );
$wgShowDebug = true;
$wgDebugToolbar = true;
$wgDebugLogFile = "$IP/debug.log";

  • Look in the directory /Applications/MAMP/Library/bin/envvars and comment out the lines which repath the dynamic linker!
  • The math extension and mediawiki ends up generating the incorrect path for the pngs. It looks like it creates something from the root of the filesystem rather than relative from localhost. For example the following generated URL will not work:
    There is a hacky fix, however. Grep for _linkToMathImage in the MediaWiki source and add the following code to replace the Apache document path:

    function _linkToMathImage() {
    $mampRoot = '/Users/<username>/Sites'; # Add this line
    $url = $this->_mathImageUrl();
    $url = preg_replace('/^' . preg_quote($mampRoot, '/') . '/', '', $url); # …and add this line.
    wfDebug("Getting the url " . $url );

Purge the wiki cache and you should be able to add Math notation to your hearts content and create pages like this:

Enjoy :).