User:Mainframe98/Vagrant

MediaWiki Vagrant.svg

This page describes how to do certain things on MediaWiki-Vagrant.

Running unit testsEdit

I recommend creating a quick script:

#!/bin/bash
export PHPUNIT_WIKI=wiki

php /vagrant/mediawiki/tests/phpunit/phpunit.php "$@"

Generating test coverageEdit

I recommend creating a quick script:

#!/bin/bash
export XDEBUG_MODE=coverage
export PHPUNIT_WIKI=wiki

php /vagrant/mediawiki/tests/phpunit/phpunit.php --coverage-html /vagrant/mediawiki/docs/coverage "$@"

This will enable coverage for XDebug 3, allowing you to keep it disabled when not using coverage related features (#Unborking Xdebug).

Unborking XdebugEdit

Xdebug is borked at the moment. You can manually install it using pecl:
  1. Install pear wherever. The home directory works fine, as long as you don't mind pear complaining about include paths, which are irrelevant for installing extensions.
    1. Download pear with wget http://pear.php.net/go-pear.phar
    2. Execute the installer with php go-pear.phar. When prompted, just press enter, the default will do.
      • The prompt about altering php.ini can be ignored (pass n)
  2. Install Xdebug, by running pecl install xdebug. You'll likely need to run this as a user with additional privileges, so prefix this with sudo
    • Note that the installer does not add pear and pecl to PATH, so you'll need to navigate to the folder with the executable! (which is in the same location as pear; pear/bin/)
  3. Check that Xdebug is installed by navigating to info.php
  • Xdebug should also automatically been updated when using the cli: you can check this by running php -v

Optional steps if Xdebug doesn't show upEdit

You shouldn't need these steps, vagrant comes with default configuration to enable xdebug both in apache and on the cli.
  1. Add extension=xdebug.so to /etc/php/7.2/apache2/php.ini. For the cli, add it to /etc/php/7.2/cli/php.ini
  2. Restart apache with sudo systemctl restart apache2

Making the remote debug actually functionEdit

No idea why it doesn't work.

Set following in /etc/php/7.2/mods-available/_remote_debug.ini:

  • xdebug.remote_connect_back=Off
  • xdebug.remote_host=10.0.2.2

Using XDebug 3.0.0Edit

Set /etc/php/7.2/mods-available/_remote_debug.ini to:

xdebug.max_nesting_level = "200"
xdebug.discover_client_host = true
xdebug.log = "/vagrant/logs/xdebug.log"
xdebug.mode = debug
xdebug.var_display_max_children = 0
xdebug.client_host="10.0.2.2"

This will make XDebug behave the same as 2.X did. var_display_max_children can be set to a different value, but the default is way too much.

Running phanEdit

Note: If you use Vagrant on Windows, you don't have to go through all this effort if you have PHP installed under Windows! Provided you have the ast extension installed, Phan runs just fine under Windows.

This is a chore, but T234240 should make this easier.

  1. Install phan as a composer dev dependency in MediaWiki.
    • Navigate to /vagrant/mediawiki and run composer require phan/phan --dev
    • Note: Recent version of MediaWiki use the mediawiki-phan-config package and will install automatically when running composer update
  2. Install pear wherever. The home directory works fine, as long as you don't mind pear complaining about include paths, which are irrelevant for running phan.
    1. Download pear with wget http://pear.php.net/go-pear.phar
    2. Execute the installer with php go-pear.phar. When prompted, just press enter, the default will do.
  3. Install the php-ast extension, by running pecl install ast. You'll likely need to run this as a user with additional privileges, so prefix this with sudo
    • Note that the installer does not add pear and pecl to PATH, so you'll need to navigate to the folder with the executable! (which is in the same location as pear; pear/bin/)
  4. Add extension=ast.so to /etc/php/7.2/cli/php.ini
  5. Check that php-ast is installed by running php -m
  6. Change the default vagrant memory size, as the default of 1.5G is insufficient to run phan, by creating a Vagrantfile-extra.rb in the vagrant root directory with the following content:
Vagrant.configure('2') do |config|
      config.vm.provider :virtualbox do |vb|
          # See http://www.virtualbox.org/manual/ch08.html for additional options.
          vb.customize ['modifyvm', :id, '--memory', '3072']
      end
end
You may replace 3072 with any higher value, as this is the new memory size of the vagrant box in megabytes.

You should now be able to run phan with /vagrant/mediawiki/vendor/bin/phan -d PATH_TO_SOMETHING -p

Simple runnerEdit

#!/bin/bash
/vagrant/mediawiki/vendor/bin/phan -d "$@" -p

Save this in ~/phan.sh and invoke with ./phan.sh /vagrant/mediawiki.