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

Time:09-29

I have zero php experience, but need to fire up an existing application that I have cloned (which is supposed to be functional), to test it quickly. I think I'm pretty close to have it working.

If I run 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

If I visit localhost:8000 however, I get enter image description here, which seems to be a Laravel 500 error page. So I am serving, which is good, but the app isn't really running.

Installations steps I have done:

  • clone the git repo for the source coe & cd to project root
  • install php, composer, npm (for javascript) & verify they work on my system (all return valid version on my system)
  • run npm install, composer install from project root to install the content of composer.lock, package.lock, which are present at project root
  • php artisan serve from project root

After I get the 500 server error, if I look at the logs (in storage/logs/laravel.logs), I find the following stack trace:

[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}
"} 

I have found a few references that note that php artisan key:generate should generate such a key for me & solve the error. However, I then get another error if I run that last command:

[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▕     }
     99100/**

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

I'm starting to think I'm missing something key upstream. Am I supposed to have some sort of .env file in the project? There are none coming in from the git repo. Could it be that some environement files/variables are not present? Or are there additional artisan/composer commands I need to be running before I can think of spinning it up?

CodePudding user response:

It seems you don't have an .env file at your root directory. You need to create an .env file which can be copied from .env.example.

After that you can run php artisan key:generate and it should work fine.

  • Related