Search code examples
laraveldocumentation

Laravel - Why laravel ask to rename .env.example to .env while .env already exist?


In Laravel 6 Documentation second paragraph of Application Key written like this

Typically, this string should be 32 characters long. The key can be set in the .env environment file. If you have not renamed the .env.example file to .env, you should do that now. If the application key is not set, your user sessions and other encrypted data will not be secure!

Why did they ask to rename it? I also found this paragraph in the Laravel older version. Is there any difference between those since they have the same content but different name?


Solution

  • If you've install Laravel using composer command.

    composer create-project laravel/laravel projectname

    you don't need renamed the .env.example file to .env. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command.

    If you clone project using git clone some folder is ignored by git so you might not get env file as well as vendor folder. Therefore, they will have to manually enter php artisan key:generate for their app to function correctly.

    More info SO answer