laravel 错误之index.php:使用git上传代码到远端,删除本地代码,再clone代码后一直报500

 最近在我的个人服务器上搭建了个laravel环境,新建了个laravel项目,可以正常运行。代码提交到gitee后删除本地代码,再从仓库拉代码,这时候发现代码跑不了了,一直报500。百度了很多方法:php artisan cache:clear、composer update、composer dumpautoload、php artisan key:generate之后一直没用。

无奈之下,只能一步步调试了:首先检查入口文件index.php,发现问题就在这边:访问public下面的其他目录时都可以正常访问,只有index.php会报500。那么,只有对index.php进行仔细分析才能找到问题所在:

";
/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell 
 */

/*
|--------------------------------------------------------------------------
| 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 nice to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';
echo "过了一会"."
"; /* |-------------------------------------------------------------------------- | 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__.'/../bootstrap/app.php'; echo "又过了一会"."
"; /* |-------------------------------------------------------------------------- | 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); echo "kernel正常"."
"; $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); echo "response正常"."
"; $response->send(); $kernel->terminate($request, $response);

 这样就发现代码停在了”kernel正常“这边。

于是,现在的主要问题就是"Illuminate\Http\Request::capture()"这个方法为什么会失败了。

仔细分析一下代码上传前后的区别,突然想起来git有一个   .gitignore 文件会在代码提交的时候过滤掉一些文件,其中默认会有vender文件夹,但这个文件夹对项目的启动没有太大影响,于是转移目光,那么还会变的就只有  .env文件了,打开项目一看,居然发现没有  .env 文件。 原来如此,真正的原因是没有 .env,大家都知道项目启动是需要app_key的,而app_key会保存在  .env 文件中,这在项目部署时是一个重点,因为要将一些隐私去掉,所以那时候 .env文件会被默认忽略。

问题解决!

 

 

 

 

 

你可能感兴趣的:(php)