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.

Installation
Vagrant and VirtualBox are both prerequisite. Both are free and open-source and available on Mac, Windows, and GNU/Linux.


 * 1) Download and install VirtualBox.
 * 2) Download and install the latest version of Vagrant from vagrantup.com (v1.1 or higher).
 * 3) Download a copy of mediawiki-vagrant:
 * tar.gz from GitHub
 * zip from GitHub
 * tar.gz from Gerrit
 * Or use Git:

If you download the zip file or tarball, you will need to extract it to a directory of your choice. Once you do that, open up a terminal or a command-prompt, and change your working directory to the location of the extracted (or git-cloned) files. From there, run  to provision and boot the virtual machine.

You'll now have to wait a bit, as Vagrant needs to retrieve the base image from Canonical, retrieve some additional packages, and install and configure each of them in turn. Our Vagrant configuration relies on Puppet to provision and configure software. See /Initial run/ for what an initial run should look like (the output you see may differ slightly).

Usage
If it all worked, you should be able to browse to http://localhost:8080/ and see the main page of your MediaWiki instance.

To access a command shell on your virtual environment, run  from the root mediawiki-vagrant directory or any of its subdirectories. (Vagrant knows which instance you are referring to by searching for a file named 'Vagrantfile' in the current directory and its parent directories.)

From there, run  to interactively evaluate PHP code in a MediaWiki context, or   to get an authenticated SQL shell on your wiki's database.

/Customizing explains how to configure your vagrant box to do more.

MediaWiki Debugging
Issue the following command if you haven't done so already:

$ vagrant up

Then issue the following command to start an SSH session in the Vagrant virtual machine:

$ vagrant ssh

Look at the Xdebug configuration:

$ sudo vi /etc/php5/apache2/conf.d/xdebug.ini

The following settings are known to work pretty well (see Yurik's virtual box on Windows 7 article for more information):

zend_extension=/usr/lib/php5/20090626/xdebug.so xdebug.idekey=default xdebug.remote_autostart=1 xdebug.remote_connect_back=1 xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_port=9000

Next, configure your IDE. The following explanation will assume you use PhpStorm.

In PhpStorm, go to File > Open Directory. Choose the mediawiki directory that is contained within your Mediawiki-Vagrant installation. If you are prompted to add files or about Git roots, just cancel those warnings unless you feel comfortable with those settings.

Now that you've created a PhpStorm project by adding the mediawiki directory, to see the basic debug settings, go to PhpStorm > Preferences > (under Project Settings) PHP > Debug. These defaults should work well with the xdebug.ini file above. But more configuration is necessary to make everything work.

Go to PhpStorm > Preferences > PHP (under Project Settings) > Servers. Click the plus (+) button to add a server. Set the Name field to something like vagrant local. Set the Host field to localhost, the Port field to 8080, and the leave the Debugger dropdwon at a value of Xdebug. Next, click the Use path mappings (select if the server is remote or symlinks are used) checkbox. On the lefthand side you will see your filesystem as expressed by the File/Directory header, and on the righthand side you can click to map the remote (virtual machine) absolute filesystem with your own (host) filesystem path. Here, you want to ensure that your own (host) filesystem path for the mediawiki directory is mapped to the remote (virtual machine) filesystem path of /vagrant/mediawiki for the Absolute path on the server. Now, click OK.

Next, in PhpStorm, go to Run > Edit Configurations. Click the plus (+) symbol to add a PHP Web Application debug configuration.

In the Server section, choose the vagrant local server configuration you just defined from the dropdown list. In the Start URL field type a relative path such as /wiki/Main_Page (or if you are a mobile developer and have enabled the MobileFrontend extension, /wiki/Main_Page?useformat=mobile). Choose whatever Browser you want to use from the dropdown list. Click OK.

TODO: finish this section.

Puppet failures
If Puppet fails to configure your machine,

This error may be caused by run-time failure to connect to Ubuntu package repositories or Gerrit. In such cases, you can simply trigger another Puppet run by running. If this doesn't work, you can try running  to trigger recreation of the virtual machine instance.

If your problem persists, please file a bug, and (if possible) attach a copy the output of the failed run.

Vagrant / VirtualBox failures
In general, Vagrant and VirtualBox get along quite well. Once in a blue moon, a VM crash in a way that causes Vagrant to lose the ability to manage the machine or inspect its status. If this should happen, you can usually fix things by running VirtualBox's management console and rebooting the machine there.

Some users may see an error:

VT-x features locked or unavailable in MSR. (VERR_VMX_MSR_LOCKED_OR_DISABLED). Result Code: NS_ERROR_FAILURE (0x80004005)

upon trying to bring up the MediaWiki VM.

Click settings, accept the recommended change, and discover that the VM image is 40G in size and a FAT filesystem only supports files up to 16G in size. VirtualBox suggests a filesystem such as ext3 with sufficient size for image files.