如何修复在 Laravel 项目中运行 vendor/bin/phpunit 时权限被拒绝的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38521329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:11:50  来源:igfitidea点击:

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

phplaravelphpunit

提问by Jin Aazoe

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

每当我vendor/bin/phpunit在 laravel 项目的根路径中执行时,它都会返回一个Permission denied错误。我该如何解决这个问题?

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

重要提示:我不想使用composer update或删除部分或全部vendor/目录然后使用,composer install因为这些方法会更改太多文件,我的主人不会同意。

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

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 vendordoesn't work.

并且 chmod 775 -R vendor不起作用。

回答by Julio Garcés Teuber

What you should do is call with php:

你应该做的是用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:

我在没有 php 解释器的情况下执行它时遇到了同样的错误:

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

Hope this helps you.

希望这对你有帮助。

回答by Babatunde Adeyemi

You can solve this by updating the Vagrantfile of your setup, particularly the fmodeof your web root synced_folderfolder.

您可以通过更新您的设置的 Vagrantfile 来解决这个问题,尤其fmode是您的 web 根synced_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

回答by Robertme

Deleting the vendorfolder and doing composer installworked for me.

删除vendor文件夹并composer install对我来说有效。

回答by Poiz

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

尝试并打开您的终端并发出以下命令:一日一用-r标志意味着变更许可也为子目录- [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 

回答by Maksim Ivanov

What you see in the vendor/bindirectory 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.

您在vendor/bin目录中看到的是symlinks。符号链接可能具有正确的权限,但它们指向的文件可能没有。确保符号链接和它们指向的文件都x启用了执行 ( ) 位。

# symlink
sudo chmod 0775 vendor/bin/phpunit

# the actual executable
sudo chmod 0775 vendor/phpunit/phpunit/phpunit