Server 500 在 linux 上启动新的 php-laravel 项目时

Server 500 while starting up a new php-laravel project on linux

我的 php 经验为零,但需要启动我已克隆的现有应用程序(应该是功能性的),以快速测试它。我想我已经很接近它的工作了。

如果我运行php artisan serve:

[franck@franck-vee appliweb]$ php artisan serve
Starting Laravel development server: http://127.0.0.1:8000
[Tue Sep 28 13:31:56 2021] PHP 8.0.10 Development Server (http://127.0.0.1:8000) started
[Tue Sep 28 13:32:00 2021] 127.0.0.1:34716 Accepted
[Tue Sep 28 13:32:00 2021] 127.0.0.1:34716 Closing
[Tue Sep 28 13:32:00 2021] 127.0.0.1:34722 Accepted
[Tue Sep 28 13:32:00 2021] 127.0.0.1:34722 [200]: GET /favicon.ico
[Tue Sep 28 13:32:00 2021] 127.0.0.1:34722 Closing

但是,如果我访问 localhost:8000,我会看到 ,这似乎是一个 Laravel 500 错误页面。所以我正在服务,这很好,但该应用程序并不是真正的 运行ning。

我完成的安装步骤:

在我收到 500 服务器错误后,如果我查看日志(在 storage/logs/laravel.logs 中),我会发现以下堆栈跟踪:

[2021-09-28 17:40:49] production.ERROR: No application encryption key has been specified. {"exception":"[object] (Illuminate\Encryption\MissingAppKeyException(code: 0): No application encryption key has been specified. at /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:79)
[stacktrace]
#0 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Support/helpers.php(263): Illuminate\Encryption\EncryptionServiceProvider->Illuminate\Encryption\{closure}()
#1 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(81): tap()
#2 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(60): Illuminate\Encryption\EncryptionServiceProvider->key()
#3 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(32): Illuminate\Encryption\EncryptionServiceProvider->parseKey()
#4 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(829): Illuminate\Encryption\EncryptionServiceProvider->Illuminate\Encryption\{closure}()
#5 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build()
#6 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve()
#7 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve()
#8 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make()
#9 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(987): Illuminate\Foundation\Application->make()
#10 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(907): Illuminate\Container\Container->resolveClass()
#11 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(868): Illuminate\Container\Container->resolveDependencies()
#12 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build()
#13 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve()
#14 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve()
#15 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make()
#16 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(156): Illuminate\Foundation\Application->make()
#17 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\Pipeline\Pipeline->then()
#19 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(670): Illuminate\Routing\Router->runRouteWithinStack()
#20 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\Routing\Router->runRoute()
#21 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\Routing\Router->dispatchToRoute()
#22 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\Routing\Router->dispatch()
#23 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#24 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#25 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#26 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#28 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#30 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#32 /home/franck/Documents/PRO/foobar/appliweb/vendor/fruitcake/laravel-cors/src/HandleCors.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle()
#34 /home/franck/Documents/PRO/foobar/appliweb/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#35 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()
#36 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#37 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\Pipeline\Pipeline->then()
#38 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#39 /home/franck/Documents/PRO/foobar/appliweb/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#40 /home/franck/Documents/PRO/foobar/appliweb/server.php(21): require_once('...')
#41 {main}
"} 
[2021-09-28 17:40:49] production.ERROR: No application encryption key has been specified. {"exception":"[object] (Illuminate\Encryption\MissingAppKeyException(code: 0): No application encryption key has been specified. at /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:79)
[stacktrace]
#0 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Support/helpers.php(263): Illuminate\Encryption\EncryptionServiceProvider->Illuminate\Encryption\{closure}()
#1 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(81): tap()
#2 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(60): Illuminate\Encryption\EncryptionServiceProvider->key()
#3 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(32): Illuminate\Encryption\EncryptionServiceProvider->parseKey()
#4 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(829): Illuminate\Encryption\EncryptionServiceProvider->Illuminate\Encryption\{closure}()
#5 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build()
#6 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve()
#7 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve()
#8 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make()
#9 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(987): Illuminate\Foundation\Application->make()
#10 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(907): Illuminate\Container\Container->resolveClass()
#11 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(868): Illuminate\Container\Container->resolveDependencies()
#12 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build()
#13 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve()
#14 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve()
#15 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make()
#16 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(205): Illuminate\Foundation\Application->make()
#17 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(179): Illuminate\Foundation\Http\Kernel->terminateMiddleware()
#18 /home/franck/Documents/PRO/foobar/appliweb/public/index.php(55): Illuminate\Foundation\Http\Kernel->terminate()
#19 /home/franck/Documents/PRO/foobar/appliweb/server.php(21): require_once('...')
#20 {main}
"} 
[2021-09-28 17:42:09] production.ERROR: file_get_contents(/home/franck/Documents/PRO/foobar/appliweb/.env): Failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): file_get_contents(/home/franck/Documents/PRO/foobar/appliweb/.env): Failed to open stream: No such file or directory at /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96)
[stacktrace]
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php(96): file_get_contents()
#2 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php(80): Illuminate\Foundation\Console\KeyGenerateCommand->writeNewEnvironmentFileWith()
#3 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php(45): Illuminate\Foundation\Console\KeyGenerateCommand->setKeyInEnvironmentFile()
#4 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Foundation\Console\KeyGenerateCommand->handle()
#5 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#6 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#7 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#8 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Container/Container.php(611): Illuminate\Container\BoundMethod::call()
#9 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#10 /home/franck/Documents/PRO/foobar/appliweb/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute()
#11 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#12 /home/franck/Documents/PRO/foobar/appliweb/vendor/symfony/console/Application.php(971): Illuminate\Console\Command->run()
#13 /home/franck/Documents/PRO/foobar/appliweb/vendor/symfony/console/Application.php(290): Symfony\Component\Console\Application->doRunCommand()
#14 /home/franck/Documents/PRO/foobar/appliweb/vendor/symfony/console/Application.php(166): Symfony\Component\Console\Application->doRun()
#15 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\Component\Console\Application->run()
#16 /home/franck/Documents/PRO/foobar/appliweb/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#17 /home/franck/Documents/PRO/foobar/appliweb/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#18 {main}
"} 

我找到了一些参考资料,指出 php artisan key:generate 应该为我生成这样一个密钥并解决错误。但是,如果我 运行 最后一个命令,我会收到另一个错误:

[franck@franck-vee appli-assurance]$ php artisan key:generate

   ErrorException 

  file_get_contents(/home/franck/Documents/PRO/kbrs/appli-assurance/.env): Failed to open stream: No such file or directory

  at vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96
     92▕     {
     93▕         file_put_contents($this->laravel->environmentFilePath(), preg_replace(
     94▕             $this->keyReplacementPattern(),
     95▕             'APP_KEY='.$key,
  ➜  96▕             file_get_contents($this->laravel->environmentFilePath())
     97▕         ));
     98▕     }
     99▕ 
    100▕     /**

      +16 vendor frames 
  17  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

我开始觉得我在上游遗漏了一些关键的东西。我应该在项目中有某种 .env 文件吗? none 来自 git 仓库。可能是某些环境 files/variables 不存在?或者是否有额外的 artisan/composer 命令我需要 运行ning 才能考虑启动它?

您的根目录中似乎没有 .env 文件。您需要创建一个可以从 .env.example.

复制的 .env 文件

之后你可以 运行 php artisan key:generate 它应该可以正常工作。