使用 Laravel 安装无法打开流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28573308/
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
Failed to Open Stream using laravel install
提问by TheCodingCat
I am trying out Laravel and after installation I get the following when attempting to start a new application:
我正在试用 Laravel,安装后我在尝试启动新应用程序时得到以下信息:
using code: laravel new blog
使用代码: laravel new blog
I get:
我得到:
PHP Warning: file_put_contents(/var/www/html/laravel_d4381b5ce250405766ef8b9fa784b256.zip): failed to open stream: Permission denied in /home/ren/.composer/vendor/laravel/installer/src/NewCommand.php on line 81
PHP Warning: ZipArchive::extractTo(): Permission denied in /home/ren/.composer/vendor/laravel/installer/src/NewCommand.php on line 99
PHP Warning: ZipArchive::close(): Invalid or unitialized Zip object in /home/ren/.composer/vendor/laravel/installer/src/NewCommand.php on line 101
Application ready! Build something amazing.
回答by Bogdan
It seems the user you're running the command with, doesn't have the necessary permissions to write to /var/www/html/. Try changing the permissions or owner of that directory. Try:
您正在运行命令的用户似乎没有必要的权限来写入/var/www/html/. 尝试更改该目录的权限或所有者。尝试:
sudo chown $USER /var/www/html
The $USERvariable contains the logged in username (in your case ren), so it will make your user the owner of that directory. Then run the installation command:
该$USER变量包含登录的用户名(在您的情况下ren),因此它将使您的用户成为该目录的所有者。然后运行安装命令:
laravel new blog
回答by Marius Cucuruz
As a noob, it took me a few good painstakingly hours to figure this out. As far as my understanding goes, you'll need to initiate the new project with laravel new <project>in a 777 directory. So you'd go like:
作为菜鸟,我花了好几个小时才弄明白这一点。据我了解,您需要laravel new <project>在 777 目录中启动新项目。所以你会这样:
### make directory and grant full permissions
sudo mkdir /var/www/laravel
sudo chmod -R 777 /var/www/laravel/
cd /var/www/laravel/
### run laravel installer
laravel new web-project
### move your project in www root
sudo mv web-project /var/www/
The last bit where you move the directory is optional and you may leave it there or move it to anywhere your vhostmight be set up.
移动目录的最后一点是可选的,您可以将其留在那里或将其移动到您的虚拟主机可能设置的任何位置。
Personal note: I was actually hoping setting up a new Laravel app to be easier than this. I'm confident however it will get easier with practice :)
个人笔记:我实际上希望设置一个新的 Laravel 应用程序比这更容易。我有信心,但练习会变得更容易:)

