【发布时间】:2018-06-25 09:56:20
【问题描述】:
又是我,
我还是这个 Laravel 世界的新手,我已经克服了很多问题,但这个问题让我发疯了。错误状态如下:
调用未定义的方法 Illuminate\Foundation\Application::run()
我不知道该去哪里找。我发现bindShared() 和share() 函数存在类似问题,但run() 没有。
我猜它是一个“核心”功能,因为它负责部署整个应用程序。
我检查了以下几点:
- htaccess(为了找到项目文件夹而修改)
- Apache 配置
- PHP 扩展(我猜它们都已启用,否则项目会给我“哎呀”错误或 500 错误
- 用于 HTML 表单的 Laravel\Collective(我正在使用它,因为以前的核心包已被弃用)
这是我的htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} (.+)/$
#RewriteRule ^ %1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/itccomercioexterior-system
RewriteRule ^(.*)$ /itccomercioexterior-system/$1 [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
这是我的index.php:
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylor@laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
try {
$app->run();
} catch(\Exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}
最后是我的树视图:
/project
├── css
│ ├── app.css
│ ├── bootstrap.css
│ ├── font-awesome.css
│ └── gridcss.css
├── favicon.ico
├── fonts
│ ├── fontawesome-webfont.eot
│ ├── fontawesome-webfont.svg
│ ├── fontawesome-webfont.ttf
│ ├── fontawesome-webfont.woff
│ └── fontawesome-webfont.woff2
├── index.php
├── js
│ ├── app.js
│ └── index.js
├── laravel
│ ├── app
│ ├── artisan
│ ├── bootstrap
│ ├── composer
│ ├── composer.json
│ ├── composer.lock
│ ├── config
│ ├── database
│ ├── package.json
│ ├── package-lock.json
│ ├── phpunit.xml
│ ├── readme.md
│ ├── resources
│ ├── routes
│ ├── server.php
│ ├── storage
│ ├── tests
│ ├── vendor
│ └── webpack.mix.js
├── media
│ ├── aduanas.jpg
│ ├── aduanas.png
│ ├── carousel001.jpg
│ ├── carousel002.jpg
│ ├── carousel003.png
│ ├── carousel004.jpg
│ ├── contacto.jpg
│ ├── curso1.jpg
│ ├── curso2.jpg
│ ├── curso3.jpg
│ ├── cursos.jpg
│ └── logo.webp
├── mix-manifest.json
├── robots.txt
├── storage
│ └── logs
└── web.config
任何见解将不胜感激!
再次感谢大家!
【问题讨论】:
-
你的第一个错误是没有遵循正确的 laravel 目录结构。恐怕你自己一个人。
-
正确的结构是什么?我阅读了如何上传到共享主机和 vps 并且大多数人都同意:或者将公共文件夹内容移动到根目录 (public_html),或者只是将 apache 重定向到公共内容。无论哪种方式,您都必须更改 index.php 中的路径,以便它可以构建应用程序。
-
在 laravel 版本 5+ 中(顺便说一下,它实际上没有
$app->run()函数)你在 laravel 文件夹中的内容需要上一级,其他所有内容都需要在 @ 987654330@ 文件夹。该公用文件夹必须是主机文档根目录。您可以将 public 的内容移动到public_html,然后将 public_html 符号链接到 public,但如果您的源代码位于主机根目录下,那么它很可能会被全世界看到 -
哦,真丢人。事实上,我已经记下了:facepalm:。你在那个结构上是正确的。为了security 101,我会更正它。谢谢!