在000WebHost部署Laravel遇helpers.php加载失败错误求助
Fatal error: Uncaught Error: Failed opening required '/storage/ssd5/191/19896191/laravel/vendor/composer/../laravel/framework/src/Illuminate/Collections/helpers.php' (include_path='.:/usr/share/pear:/usr/share/php:/usr/share/pear:/usr/share/php') in /storage/ssd5/191/19896191/laravel/vendor/composer/autoload_real.php:39 Stack trace: #0 /storage/ssd5/191/19896191/laravel/vendor/composer/autoload_real.php(43): {closure}() #1 /storage/ssd5/191/19896191/laravel/vendor/autoload.php(25): ComposerAutoloaderInit77107db52e33f59325c65f41516f3a02::getLoader() #2 /storage/ssd5/191/19896191/public_html/index.php(36): require('...') #3 {main} thrown in /storage/ssd5/191/19896191/laravel/vendor/composer/autoload_real.php on line 39
为了显示错误,已在index.php开头添加以下代码:
ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL);
部署步骤如下:
- 压缩除
public文件夹外的所有文件,同时单独压缩public文件夹; - 使用unzipper将压缩包解压到主机目录,得到对应文件结构;
- 修改
index.php文件,在两行代码中添加laravel/路径:require __DIR__.'/../laravel/vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application, we can handle the incoming request using | the application's HTTP kernel. Then, we will send the response back | to this client's browser, allowing them to enjoy our application. | */ $app = require_once __DIR__.'/../laravel/bootstrap/app.php'; - 修改
app/providers/AppServiceProvider.php文件:public function register() { $this->app->bind('path.public',function(){ return'/public_html'; }); } - 清除缓存:删除
bootstrap/cache中除.gitignore外的所有文件,同时在本地压缩前尝试过执行composer install、composer dump-autoload、composer update、composer update --no-scripts命令; - 正确配置
.env文件(数据库等信息)。
仅手动修改过composer.json,添加了以下配置项:
"config": { "optimize-autoloader": true, "platform-check": false, //This line! "preferred-install": "dist", "sort-packages": true },
此外还尝试修改.htaccess为以下内容:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>
已调整过文件夹结构,但问题仍未解决。
内容的提问来源于stack exchange,提问作者Lucas Tomic

