MediaWiki-Vagrant



MediaWiki-Vagrant is a portable MediaWiki development environment. It consists of a set of configuration scripts for Vagrant and VirtualBox that automate the creation of a virtual machine that runs MediaWiki.

The virtual machine that MediaWiki-Vagrant creates makes it easy to learn about, modify, and improve MediaWiki's code: useful debugging information is displayed by default, and various developer tools are set up specifically for inspecting and interacting with MediaWiki code, including a powerful debugger and an interactive interpreter. Best of all, because the configuration is automated and contained in a virtual environment, mistakes are easy to undo.

Quick start
If you are installing MediaWiki-Vagrant from the USB distribution, follow the steps in the README rather than the first four steps.   [http://git-scm.com/ Get Git ]   [https://www.virtualbox.org/wiki/Downloads Get the latest VirtualBox ]   [//www.vagrantup.com/downloads.html Get the latest Vagrant ]   Get the code and create your machine:  $ git clone https://gerrit.wikimedia.org/r/mediawiki/vagrant $ cd vagrant $ git submodule update --init --recursive $ ./setup.sh # or setup.bat if more approriate $ vagrant up  Running Windows? Get Git and run the git commands in a Git Bash shell. Run setup.bat from a cmd.exe shell.   If prompted, enter your Gerrit user name (recommended), or just hit Enter. When Vagrant is done configuring your machine, browse to http://127.0.0.1:8080/ to find your MediaWiki instance. The admin password is s. After installation, you may be able to re-check "Block all incoming connections and "Enable stealth mode" now that the firewall rules have been updated.


 * Use http://127.0.0.1:8080/info.php to check that Apache/PHP is up and running.
 * You might want to compare the output of the initial run of vagrant up in your terminal with this sample. The initial setup may take a long time; if it seems to hang somewhere but there are no errors, just give it a while.


 * If you're not running Windows, MediaWiki-Vagrant uses NFS to share some folders with the host machine (your computer). You need to set up your computer as an "NFS server", see e.g. [https://help.ubuntu.com/community/SettingUpNFSHowTo Ubuntu instructions].
 * If you got any puppet errors you might need to init puppet submodules, on vagrant directory run git submodule update --init


 * Vagrant rarely loses pairing with your VM. [https://github.com/mitchellh/vagrant/issues/1755</> This thread] discusses some ways to work around it (e.g. attaching old VM harddrive to the new profile)


 * Vagrant cannot be run from an encrypted directory especially if you are running on Ubuntu and setting for an encrypted home directory. To run vagrant you need to move the MediaWiki-Vagrant's directory on "/opt/" then simply launch.


 * If you have additional questions, irc>Special:MyLanguage/MediaWiki on IRC</>|IRC is a good option, specifically the channel.

Basic usage


The vagrant command-line tool on the host machine provides several subcommands for controlling your virtual machine. You've already used one: vagrant up, which turns on the virtual machine. Like most vagrant subcommands, you need to run it from the MediaWiki-Vagrant directory or one of its children. When you first run it, Vagrant will fetch a system image and set up requisite software for running MediaWiki. This takes about a hour on a broadband connection, but it only needs to happen once. When you run vagrant up in the future, it will simply boot up the machine.

vagrant ssh starts an interactive login shell on the virtual machine. It'll log you in as the user vagrant ; root access is available to via sudo, which is passwordless. Because the virtual machine is entirely sandboxed within your computer, it is configured for convenience, not security. As a rule, whenever you encounter a password prompt, the password is.

When you log in, you should see a colorful MediaWiki banner and a few reminders of useful commands.

The command hhvmsh will start an interactive PHP interpreter with MediaWiki's codebase already loaded. You can type in some code, hit 'enter', and the code will be evaluated immediately. If you start a line with '=', its computed value will be pretty-printed. Type ? for quick help or help start for additional instructions.

The  folder corresponds to the MediaWiki-Vagrant folder on your host machine, and its contents is shared. MediaWiki's code is installed in. This allows you to use your normal editor environment on your host machine to edit the MediaWiki code that runs on your virtual machine.

Use vagrant git-update to keep your git repositories and database schema up to date. This command is equivalent of performing git pull for core and all extension directories, followed by running the  script.

Log out of your virtual machine by typing logout or by pressing CTRL + D. Now that you're back in a standard command prompt, you can run vagrant halt to shut down the virtual machine and vagrant up to bring it back up. vagrant destroy will delete the virtual machine's files; this command is useful if you want to return your instance to a pristine state. (You'll need to follow up with vagrant up to provision a fresh instance.)

Using roles
MediaWiki-Vagrant sets up a basic MediaWiki instance by default, but it also knows how to configure a range of complementary software, including some popular MediaWiki extensions and their dependencies. These optional software stacks are collectively known as 'roles', and MediaWiki-Vagrant offers an easy and powerful command-line interface for managing them. <div style="width: 375px; font-family: Consolas, monaco, monospace; font-size: 13px; background-color: #333; color: #fff; padding: 1px 12px; margin:auto;"> $ vagrant list-roles # Display a list of available roles.

<div style="font-family: Consolas, monaco, monospace; font-size: 13px; background-color: #333; color: #fff; padding: 1px 12px; width: 375px;margin: auto;"> $ vagrant enable-role role # Turn on role for this machine.

<div style="font-family: Consolas, monaco, monospace; font-size: 13px; background-color: #333; color: #fff; padding: 1px 12px; width: 375px;margin: auto;"> $ vagrant disable-role role # Turn off role for this machine. Watch a short screencast demonstrating how to use roles. roles>Special:MyLanguage/MediaWiki-Vagrant/Roles</>|Roles has more information about some roles.

If you add many roles, you may need to increase memory available to the Vagrant VM. In particular, setting up the "browsertests" role involves compiling the  ruby Gem which is a memory-hungry task; if it fails try freeing some memory in the VM or increasing its memory allocation.

See the section Authoring roles below if you're interested in adding roles to MediaWiki-Vagrant.

Debugging
You can debug PHP with Xdebug if you vagrant enable-role zend. Debugging in PHP is different from other client-side debugging. Your IDE listens for incoming connections, and when you access the server with a browser, a special header instructs PHP to connect to your IDE. See MediaWiki-Vagrant/Advanced_usage for further information.


 * For Chrome users, you should get [<tvar|xdhelper>https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc</> XDebug Helper], and optionally [<tvar|clearcache>https://chrome.google.com/webstore/detail/clear-cache/cppjkneekbjaeellbfkmgnhonkkjfpdn</> Clear Cache], [<tvar|httpheaders>https://chrome.google.com/webstore/detail/http-headers/mhbpoeinkhpajikalhfpjjafpfgjnmgk</> HTTP headers], and [<tvar|modheaders>https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj</> Mod Headers]. Configure clear cache to automatically reload after clearing, and set up keyboard shortcuts (e.g. Ctrl+R for clear&reload, Ctrl+Shift+D to switch XDebugger on/off)


 * Firefox users should check out [<tvar|easyxd>https://addons.mozilla.org/en-US/firefox/addon/easy-xdebug/</> easy Xdebug].
 * Install and configure an [<tvar|compat>http://xdebug.org/docs/remote</> xdebug-compatible] IDE on your machine (Eclipse, PhpStorm, Emacs, etc)
 * In IDE, start listening for the incoming debug connection
 * In IDE, set break point at the spot that interests you
 * Enable XDebug in the browser and navigate to your vagrant installation ( http://127.0.0.1:8080/... )

Debugging Unit Tests
This method is a bit hacky, but can be used until debugging remote interpreter improves (e.g. in phpStorm 8 EAP).

This workaround lets you run MediaWiki unit tests from the browser.


 * Download [<tvar|url>http://phpunit.de/manual/4.1/en/installation.html</> phpunit.phar] file to the root of you vagrant directory.


 * Create a php file unittest.php in the root of mediawiki directory (mapped as /w on apache). Do not commit this file to the repository.


 * In the above file, change argv parameter to the name of your test file


 * Navigate to <tvar|url>http://127.0.0.1:8080/w/unittest.php</>


 * Follow debugging>#Debugging</>|#Debugging instructions to attach your debugger

Pushing commits
If you're using MediaWiki-Vagrant for development you'll probably want to push some commits to MediaWiki core or an extension's repository using git review. By default, all remotes point to the  URLs. To avoid overriding this on a case by case basis, run:

$ git config --global url."ssh://gerrit.wikimedia.org:29418/".insteadOf "https://gerrit.wikimedia.org/r/"

How do I...?

 * Check PHP version and settings
 * http://127.0.0.1:8080/info.php


 * Edit LocalSettings.php?
 * First, check that there is no role ( vagrant list-roles ) that already does what you need. If not, create a file in  directory. See README and 00-debug.php-example file.


 * Update MediaWiki code?
 * The easiest is to use vagrant git-update from the host. Or you can use regular git>Special:MyLanguage/Gerrit</>|git fetch, pull , etc. commands in   and   directories. You can run these commands on the virtual machine, but the file access will be faster on the host machine. MediaWiki-Vagrant pulls code from git master when you initially set up and/or add a role, but doesn't automatically update code after that.


 * Update system software?
 * vagrant provision does not update system packages in the VM. When you connect with vagrant ssh the login message will inform you <tt>NN packages can be updated. NN updates are security updates.</tt> In vagrant ssh:
 * to update all packages, enter sudo apt-get update && apt-get upgrade
 * for "automatic installation of security (and other) upgrades", similar to labs instances, enter sudo unattended-upgrade
 * to update to the same packages that are on production WMF servers... TODO


 * Customize Vagrant
 * You should never need to change Vagrantfile directly. There are several aspects of vagrant you can customize:
 * Core settings (git user, ports, ram, ip, port forwarding) can be customized via .settings.yaml file. See vagrant config --help and vagrant forward-port --help for instructions.
 * Perform additional steps after Vagrantfile load by creating a file called Vagrantfile-extra.rb and placing it in the same folder as Vagrantfile - it will be automatically loaded. In case of conflict, values in the 'extra' file will supersede values in this file. See example in support/ directory.


 * Add custom Puppet code?
 * Place your custom Puppet manifests in . Puppet will automatically apply any .pp files that it finds in that directory.


 * Update MediaWiki-Vagrant itself?
 * (For example, to use new roles.) In a terminal, change to the vagrant directory on the host computer and enter a regular git>Special:MyLanguage/Gerrit</>|git command such as git pull --ff-only . You will typically want to run vagrant provision after updating to apply any new puppet changes to your virtual machine.


 * Run GUI applications on the virtual machine?
 * If you have an X server installed, SSH into the virtual machine using ssh -- -X to enable X forwarding. (Mac users should [<tvar|xquartz>http://xquartz.macosforge.org/landing/</> update to the latest version of XQuartz].)


 * As an alternative, you can run the virtual machine in GUI mode, which allows you to interact with the VM as though it had a physical display. To enable GUI mode, create a file called  in the root repository folder, with this as its content:


 * Save the file and run vagrant halt followed by vagrant up . The virtual machine's display will appear in a window on your desktop.


 * Adjust the resources allocated to the VM?
 * If you'd like to allocate more or less CPU / RAM to the VM, see vagrant config --help for instructions.

Alternatively, you can do it by creating Vagrantfile-extra.rb (see support/ dir for an example):


 * Change the editor used for git commit messages?

Advanced usage
As an alternative to managing all MediaWiki settings in a single, large localsettings>Special:MyLanguage/Manual:LocalSettings.php</>|LocalSettings.php file, consider grouping your configurations by component or theme, and creating a separate PHP file in  for each group. This makes it quite easy to keep your settings organized, to temporarily disable specific configurations, and to share settings with others. MediaWiki will automatically load any PHP files in  in lexical order. You can control the order in which your configurations are set by adopting the habit of adding a two-digit prefix to each file name.

For example:

<pre style="background-color: #efefef; border: 0; display: inline-block; font-family: Consolas, monaco, monospace; margin: 0.4em 0 1em; padding: 0.2em 0.6em;"> settings.d/   ├── 10-RunFirst.php ├── 20-SomeExtension.php └── 99-RunLast.php

Note that the settings files in  are automatically created and destroyed in response to your Puppet configuration. Don't put your custom settings there, because Puppet will erase or override them. Keep your custom settings files in  instead.

Authoring roles
MediaWiki-Vagrant uses Puppet to configure MediaWiki on the virtual machine. Puppet is a configuration management tool that works by providing a domain-specific language for expressing software configurations in a declarative fashion. Files containing Puppet code are called 'manifests'. When Puppet runs, it interprets the manifests you feed it and configures the machine accordingly. MediaWiki-Vagrant's Puppet code is located in the. These roles depend on Puppet modules in. The Puppet code is generally well-documented and contains examples that demonstrate its proper usage.

Setting up labs instances
You can use labsvag>wikitech:Labsvagrant</>|Labsvagrant to configure Wikimedia Labs machines with a given MediaWiki-Vagrant role.

Bugs
If you spot a bug in MediaWiki-Vagrant, please report it. First, make sure the bug is not a known Vagrant or VirtualBox bug by searching the [<tvar|tracker-git>https://github.com/mitchellh/vagrant/issues</> Vagrant issue tracker on GitHub] and the [<tvar|bugtracker>https://www.virtualbox.org/wiki/Bugtracker</> VirtualBox bugtracker]. If it is not, go ahead and [<tvar|bugzilla>https://bugzilla.wikimedia.org/enter_bug.cgi?product=MediaWiki-Vagrant</> submit the bug to Wikimedia Bugzilla]. Clearly describe the issue and include steps to reproduce, whenever possible.

TLDR

 * git clone https://gerrit.wikimedia.org/r/mediawiki/vagrant
 * cd vagrant/
 * ./setup.sh
 * vagrant up
 * vagrant list-roles

Links

 * [<tvar|ohloh>https://www.ohloh.net/p/mediawiki-vagrant</> Project page on Ohloh]
 * [<tvar|github>https://github.com/wikimedia/mediawiki-vagrant</> MediaWiki-Vagrant on GitHub]
 * labsvag>wikitech:Labsvagrant</>|Labsvagrant configure Wikimedia Labs instances based on MediaWiki-Vagrant roles
 * hhvmvag>HHVM/Vagrant</>|HHVM/Vagrant steps necessary to enable the hhvm role on older MediaWiki-Vagrant installs