Docker + PHPStorm + Laravel Sail - Connect to container as sail

This might be something of a niche case, but I'm having some trouble with the test runner on PHPStorm. I'm running Windows 11, WSL2 (Ubuntu 20.04) and Docker Desktop, pretty much the default setup for Laravel Sail.

The integrated Xdebug stuff works fine, I'm just having trouble with the CLI Interpreter. It's set up to connect to the existing cluster and attach into the app container, since the tests need to be able to run against the PostgreSQL container.

The problem is: PHPStorm attaches as the root user. When I run tests using the built-in tools, the resulting folders/files created by the tests are all owned by the root user, instead of the "sail" user which is the default inside the container.

In short: How do I change the user that PHPStorm tries to connect into the container with?

0
5 comments

There is no direct way to specify the user for 'docker-compose exec':
youtrack.jetbrains.com/issue/PY-46794

However, you may try a workaround from this comment:
https://youtrack.jetbrains.com/issue/WI-57044/Change-user-for-docker-compose-interpreter#focus=Comments-27-6169749.0-0

Does it work?

 

0

Thanks for the help! Unfortunately not: It seems that if I edit that <type_data> element in php.xml, PhpStorm reverts all my settings whenever I start a test run.

It even forgets that I'm trying to connect to existing, and sets the project back to starting a new container.

0

Not sure if there any other workaround available, sorry :(
There is one extra suggestion in the main feature request ticket but I am not sure if it actually works and fits your scenario:
https://youtrack.jetbrains.com/issue/PY-46794/Add-option-to-choose-the-user-with-which-to-run-in-a-docker-compose-environment#focus=Comments-27-6411130.0-0

0

It can be achieved with a super simple wrapper script:

  1. Copy or mount the script into your laravel.test container (remember to mark it as executable).
  2. Configure your remote PHP interpreter in PhpStorm to use the script as "PHP Executable"

I've used this workaround for a long time, and it works flawlessly.

2

Magical, thanks Morten Scheel! Managed to get it set up on my side:

0

Please sign in to leave a comment.