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 ]  On Mac or Linux: Get NFS if it is not already installed. It is usually already installed in MacOS X. In Ubuntu, use .  [https://www.virtualbox.org/wiki/Downloads Get the latest VirtualBox ]   [//www.vagrantup.com/downloads.html Get the latest Vagrant (MW-V is unlikely to work with versions < 1.4.x) ]   Get the code and create your machine:

Enable additional MediaWiki features, e.g.: 

Today, the best way to install Vagrant itself is to download the proper package from http://www.vagrantup.com/downloads.html

It may take quite some time before the first vagrant up completes; e.g., 1 hour.

If you have deleted any old VMs you will see an error message like "...path contains non-directory or non-existent components..." and "vagrant up" will not complete.

The easiest way to fix this is to "sudo rm -rf /etc/exports".

Vagrant will re-create the /etc/exports file the next time you do "vagrant up".

'' MediaWiki-Vagrant will not run on a host that doesn't support VT-X because it specifies a 64bit guest.   The 64bit guest is needed in part because it uses use deb packages from WMF production that are only built for amd64 architecture. ''

Running Windows? Get [http://git-scm.com/download/win Git] and run the git commands in a Git Bash shell. Run setup.bat from a cmd.exe shell. </ol> <p style="font-size: 1.2em; margin-top: 1.2em;"> 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  and noticing the error message mentioned.

Could not set 'file' on ensure: Is a directory - (/etc/hhvm/php.ini
being tracked by https://phabricator.wikimedia.org/T87478

Any host

 * Be sure to use the most recent versions of VirtualBox and Vagrant if you get errors with vagrant up . Linux repositories may provide older versions that are not compatible with MediaWiki-Vagrant. (If you're running Debian, [<tvar|vbox>https://wiki.debian.org/VirtualBox</> try  ].)


 * If you got any puppet errors you might need to init puppet submodules, on vagrant directory run git submodule update --init


 * 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 get warnings that your VirtualBox Guest Additions are the wrong version, you can try installing the vagrant-vbguest plugin which updates them automatically.


 * Vagrant rarely loses pairing with your VM. [<tvar|issue>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)
 * Make sure that  repository is up to date:


 * Make sure that you have enabled virtualization in the BIOS. Sometimes this is under the Security settings.


 * Make sure your language encoding settings are UTF-8. If you get "[<tvar|url>https://github.com/bundler/bundler/issues/1570</> invalid byte sequence in US-ASCII]", try (re)setting your LANG and LC_ALL environment variables to something suitable.

For example:

Windows-specific

 * If you are on Windows and you get "guest machine entered an invalid state" - "poweroff", try downloading a 4.3.15 build of VirtualBox ([<tvar|url>https://forums.virtualbox.org/viewtopic.php?f=6&t=62615</> there is a known problem with 4.3.14 on Windows]). If that does not help, make sure you enable Hardware Virtualization Technology (VT-x or AMD-V) in BIOS. Hardware Virtualization is required. It is not an optional performance enhancement. (Some laptops require you to remove the power cable and battery for 30 seconds <tvar|link></>)


 * VirtualBox is incompatible with Microsoft's Hyper-V. If you have Hyper-V enabled -- which may be the default if you have installed Visual Studio -- you'll get the above errors trying to boot up a VM in VirtualBox. There are two possibilities:
 * Disable Hyper-V through 'Add/Remove Windows Features' in Control Panel and reboot. This will get VirtualBox working, but will prevent you from using any Hyper-V VMs you may have, such as Windows Phone emulators.
 * or, use the Hyper-V provider for Vagrant instead of VirtualBox. This may be unstable.

Mac-specific

 * NFS errors To avoid NFS errors, while installing ensure the firewall will accept connections: Apple > System Preferences > Security & Privacy > Firewall > Firewall Options. You will need to UNcheck "Block all incoming connections" and probably also UNcheck "Enable stealth mode" in order to accept the following: netbiosd, nfsd, rpc.lockd, rpc.rquotad, rpcbind, VBoxHeadless. Note, you may need to restart your computer and change the status to "Allow incoming connections" during a couple 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.
 * 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. [<tvar|ubuntu>https://help.ubuntu.com/community/SettingUpNFSHowTo</> Ubuntu instructions]. On Debian,   will work; you may need to   as well. Note that Debian's NFS server will not start without an entry in  . If   doesn't show "nfs" services running, this is likely what's going on.  Adding your home directory as the last line in   and then   will usually be good enough to get you past this chicken-and-egg problem.

Ubuntu

 * The NFS shares used by MediaWiki-Vagrant cannot be run from an encrypted directory as may be the case if you are running on Ubuntu and using an encrypted home directory. To run MediaWiki-Vagrant you can either:


 * Move the MediaWiki-Vagrant directory to an unencrypted volume (e.g. ) before running


 * Alternatively you can turn off NFS shares via


 * If you are getting port forwarding errors saying the ports are in use, you may need to open up virtualbox, entirely remove the virtual machine, and try again.


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

Debian "wheezy"
Surprise!

Your distro has an older version of the Vagrant package, you must install from the [<tvar|url>https://www.vagrantup.com/downloads.html</> official site] instead.

This is what your failure will look like otherwise:

$ ./setup.sh    Vagrant failed to initialize at a very early stage: There was an error loading a Vagrantfile. The file being loaded and the error message are shown below. This is usually caused by   a syntax error. Path: /milkyway/earth/home/you/mediawiki-vagrant/Vagrantfile Message: The mediawiki-vagrant plugin hasn't been installed yet. Please run `setup.sh`. Failed to execute command `vagrant plugin list` (pid 30351 exit 1)

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 can take 1–2 hours of CPU and wall clock time 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, external libraries, and database schema up to date. This command is equivalent of performing git pull for core and all extension and skin directories, followed by running composer update to ensure that the latest Composer managed libraries are available and finally calling the  script.

If you update from git manually you may also need to run composer update to download external libraries required by MediaWiki. You can run the  script to see if composer update is needed.

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 roles list # 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 roles enable 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 roles disable 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.

centralauth
There are some roles that require special attention, centralauth role does not run db migrations automatically via puppet and requires running those by hand. If you get errors on provisioning this role try to run this script on the extension and see the errors it outputs:

mwscript extensions/CentralAuth/maintenance/migrateAccount.php --username 'Admin' --auto

Once you get a more concrete error you probably need to know what migration you need to run from the ones here: extensions/CentralAuth/db_patches

Local MediaWiki core copy
Sometimes you may want to start over from scratch by removing the entire vagrant directory or cleaning out the vagrant/mediawiki directory. In order to speed up the vagrant provisioning process, you may want to consider keeping a local, updated clone of the MediaWiki core that you copy into vagrant/mediawiki.

for example, assuming you are cloning MediaWiki repos into ~/projects/mediawiki/ :

Update cloned repos
Update the cloned repos as often as possible/necessary.

Vagrant reload
Run vagrant reload after your initial vagrant up and after any new vagrant provision commands.

When to enable roles
Enable roles only once you've successfully run your first vagrant up.

Vagrant behind proxy
If you are behind a proxy, Vagrant might throw some [<tvar|url>https://gist.github.com/ankita-kumari/b7598a62ae209fca1db2</> errors].

You can install <tvar|proxyconf> vagrant-proxyconf </>.

It’s a plugin that allows your virtual machine to use specified proxies.

This is a quick set up guide.

For a detailed documentation you may check here.

Install the plugin:

To configure proxy settings for all softwares on all vagrant VMs, add following lines to your  (default  ).

Replace the addresses with the ip and port number of your proxy server.

Use the config.proxy.no_proxy option to list out all the sites/domains for which you might want to bypass proxy. For example,

Now when you run a <tvar|code> vagrant up </>, there shouldn’t be any warnings.

To disable the plugin set config.proxy.enabled to false or empty string ("").

You can also disable it for specific applications. For example,

MediaWiki-Vagrant prep
You may want to consider using a shell script such as [<tvar|url>https://github.com/dan-nl/mw-vagrant-prep</> mw-vagrant-prep] to prepare a directory for a MediaWiki-Vagrant install.

Provisioning
You can debug the provisioning process by running

PHP
See debug>Special:MyLanguage/Manual:How to debug#HHVM</>|Manual:How to debug#HHVM.

But first work around <tvar|phab></>.

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.

Chrome

 * 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

 * 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/... )

Log files
The mediawiki logs can be found in /vagrant/logs.

There are log files for Apache in /var/log/apache2/, but it seems they are not written to.

There is a log file for HHVM in /var/log/hhvm/.

The PHP notices, warnings, errors, uncaught exceptions are logged by HHVM to the syslog which you can see in /var/log/syslog.

The MySQL query log can be obtained by issuing <tvar|code> SET GLOBAL general_log = 'ON'; </> in a client and then looking at /var/lib/mysql/*.log.

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/p/"

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 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  from the host.  Or, to just update the code without dependencies, you can use regular git>Special:MyLanguage/Gerrit</>|git ,  , 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.


 * Run MediaWiki PHP interpreter
 * ssh to vagrant and run . You might need to run it with


 * Run MediaWiki SQL interpreter
 * ssh to vagrant and run . You might need to run it with


 * Update virtual machine software packages?
 * does not update system packages in the VM. When you connect with vagrant ssh the login message will inform that you: NN packages can be updated. NN updates are security updates. In vagrant ssh:
 * to update all packages, enter
 * for "automatic installation of security (and other) upgrades", similar to labs instances, enter
 * 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  and   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?


 * This is ideal if you want to work on your own MediaWiki site locally and let the MediaWiki-Vagrant install your dependencies for you. It's ideal if you have your own fork.  There is a distinction between a role and this use case. Roles are meant to be installed in any order and without breaking. If your fork needs different calls and get in trouble with roles, create your own class and call what you need, including roles.


 * To do so, place your custom puppet code in  with your own class, like so:

To apply your class, add it to the "classes" key in <tvar|file> </>.

You can create the file if it doesn't exist.

Then run  to apply the change via Puppet.


 * 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 . You will typically want to run   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  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  followed by  . The virtual machine's display will appear in a window on your desktop.


 * <span id="Adjust_CPU"> Adjust the resources allocated to the VM?
 * If you'd like to allocate more or less CPU / RAM to the VM, see  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?


 * Setup a custom hostname?

Go to [<tvar|url>https://wikitech.wikimedia.org/wiki/Special:NovaProxy</> Special:NovaProxy], click "Add proxy" and enter a DNS hostname, say View your new wiki at " http:// /wiki/ "


 * Make the custom hostname point to homepage of my vagrant role instead of wiki homepage?

Create a local.yaml file in the /vagrant/puppet/hieradata directory. In it, add:

Run <tvar|code> </>.


 * Run a branch of MediaWiki other than master?
 * Set the "mediawiki::branch" key in .  You can create the file if it doesn't exist.

This change has to be made BEFORE running vagrant up for the first time.

If you decide you want to do it later, make the change, destroy your current VM with, delete your existing mediawiki checkout and finally build a new VM with.

Vagrant is designed to run with the master branch, and may not work perfectly, or at all with older versions of core and/or extensions.


 * Run MediaWiki under PHP5 (Zend PHP) rather than HHVM?
 * Visit the  vhost that MediaWiki-Vagrant provisions automatically. This Apache vhost runs the same configuration as the default   vhost but using PHP5 instead of HHVM.
 * To convert all wikis in your MediaWiki-Vagrant instance to PHP5:

MediaWiki settings
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.

Vagrant Flags
Display a list of all current Vagrant flags.

After the initial, in your vagrant directory, you can then set one of the vagrant flags that appears in the config list, e.g.

Job queue
If you're testing something that needs to churn the job queue, you may need to increase the number of job runners. Currently this is not available through LocalSettings.php, but must be set in the config file for the job runner.


 * 1) Open
 * 2) Change the value for the ' ' key from   to the desired value (say,  )
 * 3) Re-provision with
 * 4) Beware this will be a difference from the git master in your code

See instructions above for adjusting CPU core count appropriately (highly recommended for CPU-bound task such as video transcoding).

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.

Some of the more useful puppet modules are:
 * mediawiki::extension: install and configure an extension (example)
 * mediawiki::import_text: create a documentation or test page on the wiki (example)
 * require_package: install a system package (example)
 * exec: execute a shell command (example)

mediawiki::import_dump
When using the puppet method, mediawiki::import_dump, make sure the dump_sentinel_page value does not contain a URL, such as Testwiki:wiki/Template:Cc-by-3.0; instead it should be Template:Cc-by-3.0. Here is one possible example:

==Setting up labs instances==

You can use labsvag>wikitech:Labs-vagrant</>|Labs-vagrant to install MediaWiki on a Wikimedia Labs instance and enable  MediaWiki-Vagrant roles in it.

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|phab>https://phabricator.wikimedia.org/maniphest/task/create/?projects=PHID-PROJ-pj7wqr7ws7gty53ssn57</> submit the bug to Wikimedia Phabricator]. Clearly describe the issue and include steps to reproduce, whenever possible.

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]
 * [<tvar|phab>https://phabricator.wikimedia.org/project/view/627/</> Issue tracker on Phabricator]
 * labsvag>wikitech:Labs-vagrant</>|Labs-vagrant 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