laravel Composer 在 /var/www/html 中找不到 composer.json 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34709720/
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 13:01:25  来源:igfitidea点击:

Composer could not find a composer.json file in /var/www/html

phpjsonlaravelubuntucomposer-php

提问by Alavaros

I'm trying to set up an environment in my Virtual Machine which is an Ubuntu 15.10. I've followed a tutorial with these steps:

我正在尝试在我的虚拟机中设置一个环境,它是 Ubuntu 15.10。我已经按照以下步骤进行了教程:

curl -sS https://getcomposer.org/installer | php
sudo mv ~/composer.phar /usr/local/bin/composer
composer global require "laravel/installer"

Then I do:

然后我做:

sudo nano ~/.profile

And I add this to end of file:

我将其添加到文件末尾:

PATH="$PATH:~/.composer/vendor/bin"

Finally:

最后:

composer global update

After these steps, I try:

在这些步骤之后,我尝试:

laravel new project

And get this error:

并得到这个错误:

PHP Warning:  file_put_contents(/var/www/html/laravel_62a1f2f16d54929f3367e5f18f937a47.zip): failed to open stream: Permission denied in /home/alavaros/.composer/vendor/laravel/installer/src/NewCommand.php on line 114
PHP Warning:  ZipArchive::extractTo(): Permission denied in /home/alavaros/.composer/vendor/laravel/installer/src/NewCommand.php on line 132
PHP Warning:  ZipArchive::close(): Invalid or uninitialized Zip object in /home/alavaros/.composer/vendor/laravel/installer/src/NewCommand.php on line 134
Composer could not find a composer.json file in /var/www/html
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

采纳答案by ordonezalex

It looks like you have a permission issue.

您似乎遇到了权限问题。

What is the output of ls -l /var/www? You should see that you have write permission (w) for public or that you are in the group listed.

的输出是ls -l /var/www什么?您应该会看到您w对 public有写权限 ( ) 或者您在列出的组中。

For example, you might see

例如,您可能会看到

drwxr-xr-x  3 root root 4096 Jul  4  2015 .

Which means you would have issues writing to /var/wwwwithout acting as root.

这意味着您在/var/www不充当root.

Simply running sudo laravel new projectmight fix your current problem, but may incur you having to use sudowhenever you want to work.

简单地运行sudo laravel new project可能会解决您当前的问题,但可能会导致您在sudo想要工作时必须使用它。

A better solution would be to give yourself access to this directory:

更好的解决方案是让自己访问此目录:

sudo chmod o+w /var/www/

Running this command will give all (other) users (including you) on this machine write access to /var/www

运行此命令将尽数(Ø本机上疗法),用户(包括你)w ^仪式访问/var/www