错误 - Laravel 5 中需要 bootstrap/../vendor/autoload.php) index.php 第 22 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37157770/
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
Error - required bootstrap/../vendor/autoload.php) index.php line 22 in Laravel 5
提问by dev85
I'm working on Laravel 5.2 framework and run first time project
我正在研究 Laravel 5.2 框架并运行第一次项目
When i run root link display error:
当我运行根链接时显示错误:
Warning: require(/home/ubuntu/workspace/../bootstrap/autoload.php): failed to open stream: No such file or directory in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0028 236248 1. {main}() /home/ubuntu/workspace/index.php:0 Fatal error: require(): Failed opening required '/home/ubuntu/workspace/../bootstrap/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0028 236248 1. {main}() /home/ubuntu/workspace/index.php:0
Before i call composer install
在我调用 composer install 之前
Its my application/.htpaccess:
它是我的应用程序/.htpaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^(.*)$ public/ [L]
</IfModule>
routes.php
路由文件
Route::get('/', function () {
return view('welcome');
});
application/index.php
应用程序/index.php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
EDIT:
编辑:
I replaced in index.php to
我在 index.php 中替换为
require __DIR__.'/../vendor/autoload.php';
But display error:
但显示错误:
Warning: require(/home/ubuntu/workspace/../vendor/autoload.php): failed to open stream: No such file or directory in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0004 233376 1. {main}() /home/ubuntu/workspace/index.php:0 Fatal error: require(): Failed opening required '/home/ubuntu/workspace/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/index.php on line 22 Call Stack: 0.0004 233376 1. {main}() /home/ubuntu/workspace/index.php:0
I have folder vendor in root directory. How me solve this issue? Thank you.
我在根目录中有文件夹供应商。我如何解决这个问题?谢谢你。
回答by Kris1
I had the same issue but bellow command over the composer sort out everything for me.
我遇到了同样的问题,但下面的作曲家命令为我整理了所有内容。
composer update --no-scripts
composer update --no-scripts
Sometimes when you run: composer install
you got that error too, so the best option is first to run: composer install --no-scripts
and then run composer install normally.
有时当你运行时:composer install
你也会遇到那个错误,所以最好的选择是先运行:composer install --no-scripts
然后正常运行 composer install。
回答by bcmcfc
__DIR__
is an absolute path to the directory of the script that you're running.
__DIR__
是您正在运行的脚本目录的绝对路径。
Get a terminal and cd
to the directory where this script lives. From there, use ls
together with paths such as up one directory (../
) and the tab-based autocompletion to find the path that you need to use to locate the autoload.php
from your index script.
获取终端并cd
转到此脚本所在的目录。从那里,ls
与诸如向上一个目录 ( ../
) 和基于选项卡的自动完成之类的路径一起使用以查找您需要使用的路径来autoload.php
从索引脚本中定位。
If you get a result like this:
如果你得到这样的结果:
$ ls ../public/index.php
ls: cannot access ../public/index.php: No such file or directory
Then you know the file doesn't exist at the path specified.
然后您知道该文件在指定的路径中不存在。
I feel it's better to answer this question by telling you how to find it rather than guessing at where it should be.
我觉得最好通过告诉您如何找到它而不是猜测它应该在哪里来回答这个问题。
回答by Parvez Rahaman
I think it's the issue in your composer.json because i also had the same.
我认为这是您的 composer.json 中的问题,因为我也有同样的问题。
Please replace your whole "scripts" object in composer.json with this..
请用这个替换你在 composer.json 中的整个“脚本”对象..
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
Now try to run composer install if not works then composer update.
现在尝试运行 composer install 如果不起作用然后 composer update 。