17

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?

Yohannes Taye
  • 217
  • 1
  • 4
  • 8

6 Answers6

19

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.

Kenny Evitt
  • 9,291
  • 5
  • 65
  • 93
Alexey Mezenin
  • 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
4

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

Andrew
  • 18,680
  • 13
  • 103
  • 118
derdida
  • 14,784
  • 16
  • 90
  • 139
2

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.

Tim
  • 6,281
  • 3
  • 39
  • 49
2

don't forget that .env is a hidden file, so you need to allow file explorer to "see" hidden files.

0
  1. Duplicate the Readme.md file in your project using your IDE
  2. Edit the duplicate to .env
  3. Copy content from .env.example
  4. Paste it in your .env file
  5. Run php artisan key:generate
Solomon Darku
  • 357
  • 2
  • 6
  • 2
    What'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
-2

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.

TeachMeJava
  • 640
  • 1
  • 13
  • 35