Skip to main content

Executing Drupal Console commands on a project with DrupalVM using vagrant-exec plugin

I am currently working on a project where we are using DrupalVM as composer dependency.

Since ssh into the VM machine to execute commands could be a little cumbersome, and providing a site configuration file to take advantage of the --target option to execute commands remotely was not an option, because the generate commands can not be executed remotely if you want to use the interactive mode.

My options got narrowed to execute vagrant ssh and run commands within the VM (which I already mentioned I am not a big fan) or take advantage of the vagrant-exec plugin.

I decided to give a try to the vagrant-exec plugin and this what you need to do to use it in your project when DrupalVM is required via composer.

Install plugin

Execute plugin install command.

Plugin configuration

Create or update your config/Vagrantfile.local file with the following configuration:

Execute command using plugin

After this easy steps you can now execute DrupalConsole or any other shell commands against the VM without the need to shh into the machine.