'How to solve "bash: vendor/bin/grumphp: Permission denied" in WSL 2?

docker-compose my-app up -d && docker-compose my-app exec app bash, then vendor/bin/grumphp run worked when my project was on Windows filesystem. Then I moved it to WSL 2 (for speed).

Now:

vendor/bin/grumphp run # bash: vendor/bin/grumphp: Permission denied

I also tried php vendor/bin/grumphp run as suggested in a similar question, and it sort of works, but not really:

Running task 1/6: phpcs... ✘
Running task 2/6: phplint... ✘
Running task 3/6: phpmd... ✘
Running task 4/6: phpstan... ✘
Running task 5/6: phpversion... ✔
Running task 6/6: yamllint... ✔
             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
         ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
       ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
  ▄███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 █▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄███████                       ██████████
     ███████▀  ▀▀▀▀▀▄      ▄▀▀▀▀▀     █████ ▀
      ▐████      ▐██        ▐██        ████▌
      ████▌                            ███
       ▌██▌           ▄▄ ▄▄           ▐███
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███
         ██▄ ▐███████████████████████████
        █▀███████████▀     ▀▀███████████
          ██████████▄███████▄███████████
         ▐█████████████████████████████
          █████████████████████████████
           ██ █████████████████████▐██▀
            ▀ ▐███████████████████▌ ▐▀
                ████▀████████▀▐███
                 ▀█▌  ▐█████  ██▌
                        ██▀   ▐▀

       ██████████████████████████████████
       █░░░░░░▀█▀░░░░░░▀█░░░░░░▀█▀░░░░░▀█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░░░░░▄█░░▄▄▄▄▄█
       █░░▐█▌░░█░░░██░░░█░░░░████░░░░░░░█
       █░░░█░░░█▄░░░░░░▄█░░░░████▄░░░░░▄█
       ██████████████████████████████████


phpcs
=====

The executable for "phpcs" could not be found.

phplint
=======

The executable for "parallel-lint" could not be found.

phpmd
=====

The executable for "phpmd" could not be found.

phpstan
=======

The executable for "phpstan" could not be found.
To skip commit checks, add -n or --no-verify flag to commit command

How to correctly solve my problem?

I'm not too fond of using sudo chmod, but right now any working solution will do.



Solution 1:[1]

Well, "permission denied" should be an obvious clue, but here we are.

  1. Go to bash on your container. It'll open on root of your project which is likely /var/www/.

  2. Use ls -la ./vendor/bin/ to list all binaries and check if they are executable and have the correct owner. Values in the first column look something like -rwxr-xr-x. You can ignore the first bit, which is followed by three groups of three bits. The first group tells you the permissions of the user owner, the second group of the group owner, and the third of all others. In each group, the first bit tells you if the file is readable, the second if it's writeable, and the third if it's executable. The values in the third and the fourth column tell you the user and group owners respectively.

  3. Use chmod +x ./vendor/bin/<file> make the files executable, and use chown 1000:1000 ./vendor/bin/<file> to change their owner. Replace with each of the following: grumphp, phpmd, phpstan, phpunit and/or whatever else you need.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 s3c