今日もメモをのこそう

あとでみるメモ代わり

Laravelをgit cloneしてみたら500エラーになった

勉強がてら、Laravelをいじりgitで管理してみたところ発生した事象

結論

Laravelでgit cloneしたときは特定の手順が必要
git cloneしたLaravelプロジェクト内で以下の手順を実施すると画面表示される。

$ composer install
$ cp .env.example .env
$ php artisan key:generate

.envは環境情報が入ってるので必要に応じて変更する必要があるが、いったんは画面表示までを目標としてるので完了。

気づくまでの流れ

git commitしたときにvenderフォルダはコミットしてなかったので、まずはcomposer installを実施した。 だが、アクセスすると、storage/logs/laravel.logに以下のようなログが出る。

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/www/laravel/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:79)
[stacktrace]

何やら鍵がないらしい。コマンドが用意されているらしいので実行すると、、、エラーになる。

$ php artisan key:generate

   ErrorException 

  file_get_contents(/home/www/laravel/.env): Failed to open stream: No such file or directory

  at vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:107
    103▕     {
    104▕         file_put_contents($this->laravel->environmentFilePath(), preg_replace(
    105▕             $this->keyReplacementPattern(),
    106▕             'APP_KEY='.$key,
  ➜ 107▕             file_get_contents($this->laravel->environmentFilePath())
    108▕         ));
    109▕     }
    110▕ 
    111▕     /**

      +16 vendor frames 
  17  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

enviromentFilePath()がないというエラー。
ということで作成する。Laravelのサンプルファイルをそのまま使う。(内容は適宜変える必要があるかも)

$ cp .env.example .env 

この後、再度実施する。

$ php artisan key:generate
Application key set successfully.

問題なく実行できたので画面を見ると、Laravelが起動できた。