Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate .env file for laravel?

From the documentation I see it's possible to create a laravel project via laravel installer:

$laravel new blog 

or via composer:

$composer create-project laravel/laravel --prefer-dist 

If I try the first way .env file is not created. How can I ask laravel,artisan or composer to create a .env file for me?

like image 298
koalaok Avatar asked Apr 28 '15 09:04

koalaok


People also ask

How do I create an .env file?

In the explorer panel, click on the New File button as shown in the following screenshot: Then simply type in the new file name . env ...

What is .env file in Laravel?

. env file, as its name suggest, is a local where you put all your environment setup, such as database credentials, cache drivers and etc. Everything that is about the server that the project is running, and may have different values for different servers, are setup here.

Where is .env located in Laravel?

env file must be in the root directory of your Laravel app. There's no way to change the file location (and I think there's no point too). Moreover, the root folder SHOULDN'T be a public folder, as . env shouldn't be exposed to a public access, otherwise the main security aim of it would be completely lost.


1 Answers

Just tried both ways and in both ways I got generated .env file:

enter image description here

Composer should automatically create .env file. In the post-create-project-cmd section of the composer.json you can find:

"post-create-project-cmd": [   "php -r \"copy('.env.example', '.env');\"",   "php artisan key:generate" ] 

Both ways use the same composer.json file, so there shoudn't be any difference.

I suggest you to update laravel/installer to the last version: 1.2 and try again:

composer global require "laravel/installer=~1.2" 

You can always generate .env file manually by running:

cp .env.example .env php artisan key:generate 
like image 52
Limon Monte Avatar answered Sep 23 '22 01:09

Limon Monte