How to fix permission denied while running vendor/bin/phpunit in a laravel project
Asked Answered
M

7

10

Whenever I execute vendor/bin/phpunit in root path of my laravel project, it gives back a Permission denied error. How can I fix this problem?

Important: I don't want to use composer update or delete some or all the vendor/ dir then use composer install as these methods will change too much files, which my master will not agree.

ps: lrwxrwxrwx 1 work work 26 Jul 21 07:10 phpunit -> ../phpunit/phpunit/phpunit

-rwxrwxrwx 1 work work 1199 Jul 22 08:19 ./vendor/phpunit/phpunit/phpunit

and chmod 775 -R vendor doesn't work.

Muriel answered 22/7, 2016 at 8:7 Comment(7)
Check the right on vendor/bin/phpunitZhdanov
lrwxrwxrwx, I hope this issue is that easy,but it is notMuriel
Are you logged as work?Zhdanov
yep,I logged in as workMuriel
chown group apache www-datda:www-dataDoorbell
vendor/bin/phpunit is a symbolic link to ../phpunit/phpunit/phpunit check the right there.Zhdanov
@Vuldo -rwxrwxrwx 1 work work 1199 Jul 22 08:19 ./vendor/phpunit/phpunit/phpunitMuriel
V
36

What you should do is call with php:

$ php ./vendor/bin/phpunit
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

I get the same error tying to execute it without php interpreter:

$ ./vendor/bin/phpunit
bash: ./vendor/bin/phpunit: Permission denied

Hope this helps you.

Vannoy answered 15/3, 2017 at 15:52 Comment(4)
THANK YOU!!!! Even the composer vendor binary documentation does not say this. getcomposer.org/doc/articles/vendor-binaries.mdGive
This is a valid workaround, but it doesn't solve the permission issue. If it works with php, but doesn't work without php, it means that the actual executable in vendor/phpunit/phpunit/phpunit does not have the x bit on.Rudbeckia
Hi @MaksimIvanov I agree with you, but at the time I wrote this answer make files executable (eg: chmod a+x) did not fix it. Currently, I am not able to replicate the issue anymore so can not tell why this happens and if there is any other solution.Parthenope
if you have more PHP versions, make sure you are calling the right one e.g. php7.1 ./vendor/phpunit/phpunit/phpunitSatanic
D
7

Deleting the vendor folder and doing composer install worked for me.

Dietz answered 5/3, 2018 at 8:18 Comment(2)
change my project folder name and user ownership, I think this is the best approach for my case. thanksRamayana
same for me, i installed dependency with composer out of container context, i deleted the folder and i started the container : docker exec -ti <container_id> bash and then rm vendo and composer installAdventuress
R
6

What you see in the vendor/bin directory is symlinks. Symlinks might have the right permissions, but the files they are pointing to might not. Ensure that both symlinks and the files they are pointing to have the execute (x) bit on.

# symlink
sudo chmod 0775 vendor/bin/phpunit

# the actual executable
sudo chmod 0775 vendor/phpunit/phpunit/phpunit
Rudbeckia answered 18/6, 2019 at 16:25 Comment(0)
D
4

You can solve this by updating the Vagrantfile of your setup, particularly the fmode of your web root synced_folder folder.

Change:

config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=666"]

to :

config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=777"]

For scotch-box,

Change:

config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

to :

config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=777"]

After doing this, reload your configuration:

$ vagrant reload
Defile answered 9/12, 2016 at 3:16 Comment(2)
Who said anything about vagrant? Im marking this down as the question never mentions vagrant.Buchbinder
While you are absolutely right that no Vagrant was mentioned in the question, it seems to be a common unmentioned problem connected with this error message. At least it fixed it for me.Damle
T
1

Try and open your terminal and issue the command: The 1st one with the -R Flag means change permission also for sub-directories - R ecursive

sudo chmod 777 -R PATH_TO/vendor

sudo chmod 777 PATH_TO/vendor/phpunit/phpunit

sudo chmod 777 PATH_TO/vendor/phpunit/phpunit/phpunit && chmod +x PATH_TO/vendor/phpunit/phpunit/phpunit 
Teddie answered 22/7, 2016 at 8:16 Comment(3)
thx a lot,I used /vendor/bin/php* in the 3rd command,but it still gives me a :Permission denied,hahaha...Muriel
@JinAazoe not /vendor/bin/php but /vendor/bin/phpunit ... sorry... check again... think the problem is because you are all files in /bin directory are sym-Links... so the code was again updated ;-)Teddie
thank you again,but doesn't work,I think simply chmod cant save my ass ,I think it has something to do with the laravel framworkMuriel
F
-1

When on linux, scripts won't be executed on filesystem mounted with noexec option

do a

mount | grep noexec

and see if your filesystem has execution disabled

Frostwork answered 11/1 at 14:15 Comment(0)
G
-1

I have also faced this error when writing a testing bash script(run-tests.sh) for a CI/CD pipeline. 

chmod +x ./vendor/bin/phpunit

Worked for me

Gaffer answered 25/6 at 21:3 Comment(2)
stackoverflow.com/a/56653400Oviparous
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Verge

© 2022 - 2024 — McMap. All rights reserved.