Using n98-magerun2 dev:console on Magento Cloud

Published: June 9, 2020

Tags:

n98-magerun2’s dev:console feature can come in quite handy for debugging production issues. However, if you try to run it on Magento Cloud, you’ll get an error due the read only filesystem:

$ var/n98-magerun2.phar dev:console

In ErrorHandler.php line 61:

  User Notice: Writing to /app/<<REDACTED>>/.config/psysh is not allowed. in phar:///app/<<REDACTED>>/var/n98-magerun2.phar/vendor/psy/psysh/src/ConfigPaths.php on line 228


dev:console [-a|--area AREA] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [--root-dir [ROOT-DIR]] [--skip-config] [--skip-root-check] [--skip-core-commands [SKIP-CORE-COMMANDS]] [--] <command> [<cmd>]

This issue can be resolved by using the XDG_CONFIG_HOME environment variable as documented in this GitHub issue.

Since ~/var is writable on Magento Cloud we can use that.

$ XDG_CONFIG_HOME=~/var/ var/n98-magerun2.phar dev:console
Magento 2.3.3 Enterprise initialized ✔
At the prompt, type help for some help.

To exit the shell, type ^D.
Psy Shell v0.9.12 (PHP 7.3.12 — cli) by Justin Hileman
New version is available (current: v0.9.12, latest: v0.10.4)
>>>

This allows us to use dev:console on Magento Cloud.


Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.