John
John

Reputation: 4981

Laravel php artisan key:generate in production

On my production server I set the env var APP_ENV=production. With this config laravel will not use .env file but it will use env var declared on the server.

But I have a problem when I run this command php artisan key:generate because I'll get this error:

In KeyGenerateCommand.php line 96:
                                                                               
  file_get_contents(/app/.env): failed to open stream: No such file or directory

Just for this command laravel need the .env file. So actually I create an empty .env file to make it works but it's ugly...

Do you have any solution ? or maybe this command is useless in production env ?

Upvotes: 1

Views: 6315

Answers (3)

Benjamin
Benjamin

Reputation: 361

If you don't want to use .env files in production you can pass --show to the key:generate command to only print it and the store it in an environment variable:

$ APP_KEY=$(php artisan key:generate --show --no-interaction)

Upvotes: 0

Mansur Oguslu
Mansur Oguslu

Reputation: 13

You can also run this :

sudo php artisan key:generate

Before doing it make sure you are in the folder, for example :

cd /var/www/html/your_folder

Upvotes: 0

Tim Lewis
Tim Lewis

Reputation: 29278

When you push a Laravel project to production, you need to generate a .env file, since that file is not committed. You should have a .env.example, which you can copy and modify as required:

cp .env.example .env

Then you can run php artisan key:generate to set the App Key.

Upvotes: 3

Related Questions