Search code examples
dockerphpstormphpstan

PhpStorm with PHPStan in Docker doesn't work


When using the System PHP interpreter for PHPStan, I get an error that the PHP version mismatches with the one being used in the Docker, see picture.

enter image description here

But when I set PHPStan to use the PHP interpreter inside the Docker container, I get an error "input device is not a TTY".

enter image description here

Anyone got any ideas how to get this running? Here's the rest of the config:

enter image description here enter image description here


Solution

  • Speaking in general (from the docker-compose exec docs):

    Commands are by default allocating a TTY, so you can use a command such as docker-compose exec web sh to get an interactive prompt.

    To disable this behavior, you and JetBrains/PhpStorm devs could use -T flag to disable pseudo-tty allocation when executing the command, i.e.:

    docker-compose exec -T web php /path/to/some/file.php
    

    Or set the COMPOSE_INTERACTIVE_NO_CLI environment variable to 1 before running docker-compose exec:

    export COMPOSE_INTERACTIVE_NO_CLI=1
    

    In case of PHP Interpreter configuration in PhpStorm (since you do not execute that command yourself), you can set that env variable in the PHP Interpreter settings:

    enter image description here
    (the screenshot is take from this comment)

    Here is PhpStorm ticket to watch after (star/vote/comment) to get notified with any progress: https://youtrack.jetbrains.com/issue/WI-71289

    Another option to try:

    I updated my docker and switched from using docker-compose to the docker compose plugin (by checking "Use Compose V2" under "Settings/Preferences | Build, Execution, Deployment | Docker | Tools"), and now it works, so it might be a docker-compose specific problem.