I'm new to laravel and i recently pulled a project from git-hub and it wouldn't run because it's missing the .env file i tried composer install but that didn't work. Is there any other way to generate the .env file?
-
btw the idea of not having .env file on git, because it contains user sensitive information. – Maytham Fahmi Aug 20 '16 at 11:53
6 Answers
You can download the standard env.example file from the Laravel source code, rename it to .env
and edit it. Just set up correct DB credentials, etc.
Don't forget to run the php artisan key:generate
command which will generate an application (encryption) key and add it to the .env
file.

- 9,291
- 5
- 65
- 93

- 158,981
- 26
- 290
- 279
-
I get that you can copy it from the source code off Laravels repo but everytime im cloning a project I must do this? I found a command but it doesn't seem to work, at least for me: ```copy .env.example .env``` it outputs ```zsh: command not found: copy``` into the terminal – Eduardo Sep 09 '21 at 19:28
-
@Eduardo `copy` command runs only in windows os. For zsh, use `cp` – risingStark Sep 14 '21 at 17:02
Just open an editor and create an .env file. Its a simple Text File.
And its ignored by git, because it contains sensitive data.
Edit: Normally there should be an .env.example file it the folder (which is not ignored by git by default), you can rename it to .env
After running composer create-project --prefer-dist laravel/laravel
not all files are installed, including .env.example
.
curl https://raw.githubusercontent.com/laravel/laravel/master/.env.example > .env
php artisan key:generate
curl https://raw.githubusercontent.com/laravel/laravel/master/.gitignore > .gitignore
curl https://raw.githubusercontent.com/laravel/laravel/master/.gitattributes > .gitattributes
curl https://raw.githubusercontent.com/laravel/laravel/master/.editorconfig > .editorconfig
.gitignore
is important because it prevents the newly created .env
from being commited.

- 6,281
- 3
- 39
- 49
don't forget that .env is a hidden file, so you need to allow file explorer to "see" hidden files.

- 73
- 5
- Duplicate the Readme.md file in your project using your IDE
- Edit the duplicate to .env
- Copy content from .env.example
- Paste it in your .env file
- Run
php artisan key:generate

- 357
- 2
- 6
-
2What's the point of duplicating the README.md, renaming it, and then replacing all of its contents? Couldn't one just create a new file with the desired contents? – Kenny Evitt Aug 06 '18 at 19:05
For me, it is invisible in VisualStudio too.
So I could not rename the .env.example
, because it cause failed error duo to .env
is already exist.
But I found it in windows explorer and opened it by NotePad to edit it.
I hope it works for you, too.

- 640
- 1
- 13
- 35