Page MenuHomePhabricator

Phan should work out of the box on MediaWiki-Vagrant
Closed, ResolvedPublic

Description

phan requires the ast php extension to do its work. Installing it on MediaWiki-Vagrant, however, is a chore.
It should really just be as easy as apt-get install php7.2-ast, instead of having to install pear, manually set up pear in PATH, then use pecl to compile php-ast and add it to php.ini.

Based on T221923: Please import php-xdebug to apt.wm.o component/php72, it should be imported in component/php72, just like php-xdebug was.

Event Timeline

jijiki triaged this task as Medium priority.Oct 14 2019, 2:25 PM

@Mainframe98 Would you mind describing how you did get ast-php installed in your Vagrant? (Since I'm struggling with the same).

@Mainframe98 Would you mind describing how you did get ast-php installed in your Vagrant? (Since I'm struggling with the same).

I've documented this on https://www.mediawiki.org/wiki/User:Mainframe98/Vagrant, but I'll include it here too:

  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 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.
  2. 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
    1. 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. Add extension=ast.so to /etc/php/7.2/cli/php.ini
  4. Check that php-ast is installed by running php -m
  5. 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.

Reedy renamed this task from It should be possible to install php-ast using apt-get on MediaWiki-Vagrant to Phan should work out of the box on MediaWiki-Vagrant.Apr 15 2021, 12:29 AM

Hmm. So that wants to install PHP 7.0...

I guess this is blocked by T256822: [EPIC] Upgrade MediaWiki-Vagrant to Debian Buster... Though https://packages.debian.org/buster/php-ast might be a bit too old..

Though https://packages.debian.org/buster/php-ast might be a bit too old..

Confirming this. We need at the very least 1.0.1, or most likely 1.0.10 due to the new PHP 8 syntax. Debian bullseye has 1.0.10.

With Buster and 7.4, sudo apt install php7.4-ast works out of the box, and installs 1.0.10. So I assume this is not an issue anymore?

Change 850240 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/vagrant@master] Add php-ast to support Phan

https://gerrit.wikimedia.org/r/850240

Change 850240 merged by jenkins-bot:

[mediawiki/vagrant@master] Add php-ast to support Phan

https://gerrit.wikimedia.org/r/850240

Tgr claimed this task.
vagrant@test:/vagrant/mediawiki$ composer phan
> phan -d . --long-progress-bar
[info] Disabling Xdebug: Phan is around five times as slow when Xdebug is enabled (Xdebug only makes sense when debugging Phan itself)
[info] To run Phan with Xdebug, set the environment variable PHAN_ALLOW_XDEBUG to 1.
[info] To disable this warning, set the environment variable PHAN_DISABLE_XDEBUG_WARN to 1.
[info] To include function signatures of Xdebug, see .phan/internal_stubs/xdebug.phan_php
[debug] Checking PHAN_ALLOW_XDEBUG
[debug] Because xdebug was installed, Phan will restart.
[debug] The Xdebug extension is loaded (3.0.3) xdebug.mode=debug
[debug] Process restarting (PHAN_ALLOW_XDEBUG=internal|3.0.3|1|*|*)
[debug] Running /usr/bin/php7.4 -n -c /tmp/nfRs1k /vagrant/mediawiki/vendor/bin/phan -d . --long-progress-bar
PHP Deprecated:  Directive 'track_errors' is deprecated in Unknown on line 0

Deprecated: Directive 'track_errors' is deprecated in Unknown on line 0
WARNING: php-ast 1.0.10 is being used with Phan 5. php-ast 1.0.11 or newer is recommended for compatibility with plugins and support for AST version 85.
php-ast can be installed in the following ways:

1. Unix (PECL): Run 'pecl install ast' and add extension=ast.so to your php.ini.

2. Unix (Compile): Download https://github.com/nikic/php-ast then compile and install the extension as follows:

   cd path/to/php-ast
   phpize
   ./configure
   make
   sudo make install

   Additionally, add extension=ast.so to your php.ini file.
For more information, see https://github.com/phan/phan/wiki/Getting-Started#installing-dependencies
(Set PHAN_SUPPRESS_AST_DEPRECATION=1 to suppress this message)
Parsing files...
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░   54 / 6989 (  2%) 77MB
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  108 / 6989 (  2%) 77MB
...
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 5076 / 6989 ( 72%) 1039MB
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░[debug] Restarted process exited 9
Script phan -d . --long-progress-bar handling the phan event returned with error code 9

Being one patch version off from what's recommended is not great but we can probably live it.

The memory requirements are more problematic - the default vagrant_ram setting is 512. I think around 5000 would be needed for a successful run. Not sure if something could/should be done about that.

I've successfully run phan with a memory limit of 3072, but that was a while ago. I'll go try it now.

We could do three things:

  1. Bump memory limit in the definitions.rb
  2. Add an instruction to edit vagrant_ram in settings.yaml
  3. Make phan a separate role that installs php-ast separately and increases the memory limit

The memory requirements are more problematic - the default vagrant_ram setting is 512. I think around 5000 would be needed for a successful run. Not sure if something could/should be done about that.

My machine started with 1536, which wasn't enough. Neither was 3072, but it came close. 4096 works but might be too small in the future.

Bump memory limit in the definitions.rb

I would rather not not make Vagrant take an extra 4G that won't be needed by most people.

Add an instruction to edit vagrant_ram in settings.yaml

It can be done via vagrant config vagrant_ram 4096; I'm just not sure if we want something more discoverable.

Make phan a separate role that installs php-ast separately and increases the memory limit

That would be the nice approach, I think.

Make phan a separate role that installs php-ast separately and increases the memory limit

That would be the nice approach, I think.

I've create T321987 for this.