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?
This question is related to
laravel
installation
composer-php
laravel-5
environment
In windows OS, you can open command prompt, change directory to your project directory.
Example,
My project directory
E:\xampp\htdocs\my_project
You can type into your Command prompt like this (hit enter each line):
E:
cd xampp\htdocs\my_project
Then you can type,
copy .env.example .env
If you are using Linux, you can type cp, instead of copy
.env
files are hidden by Netbeans. To show them do this:
Tools > Options > Miscellaneous > Files
Under Files Ignored be the IDE is Ignored Files Pattern:
The default is
^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!(htaccess|git.+|hgignore)$).*$
Add env to the excluded-not-excluded bit
^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!(env|htaccess|git.+|hgignore)$).*$
Files named .env
now show.
create .env using command!
composer run post-root-package-install or sudo composer run post-root-package-install
There's another explanation for why .env
doesn't exist, and it happens when you move all the Laravel files.
Take this workflow: in your project directory you do laravel new whatever
, Laravel is installed in whatever
, you do mv * ..
to move all the files to your project folder, and you remove whatever
. The problem is, mv
doesn't move hidden files by default, so the .env
files are left behind, and are removed!
This is an old thread, but as it still gets viewed and recently active "26" days ago as of this post, here is a quick solution.
There is no .env file initially, you must duplicate .env.example as .env.
In windows, you can open a command prompt aka the CLI and paste the exact code below while inside the root directory of the project. Must include the ( at the start line without space.
(
echo APP_NAME=Laravel
echo APP_ENV=local
echo APP_KEY=
echo APP_DEBUG=true
echo APP_URL=http://localhost
echo.
echo LOG_CHANNEL=stack
echo.
echo DB_CONNECTION=mysql
echo DB_HOST=127.0.0.1
echo DB_PORT=3306
echo DB_DATABASE=homestead
echo DB_USERNAME=homestead
echo DB_PASSWORD=secret
echo.
echo BROADCAST_DRIVER=log
echo CACHE_DRIVER=file
echo SESSION_DRIVER=file
echo SESSION_LIFETIME=120
echo QUEUE_DRIVER=sync
echo.
echo REDIS_HOST=127.0.0.1
echo REDIS_PASSWORD=null
echo REDIS_PORT=6379
echo.
echo MAIL_DRIVER=smtp
echo MAIL_HOST=smtp.mailtrap.io
echo MAIL_PORT=2525
echo MAIL_USERNAME=null
echo MAIL_PASSWORD=null
echo MAIL_ENCRYPTION=null
echo.
echo PUSHER_APP_ID=
echo PUSHER_APP_KEY=
echo PUSHER_APP_SECRET=
echo PUSHER_APP_CLUSTER=mt1
echo.
echo MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
echo MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
)>".env"
Just press enter to exit the prompt and you should have the .env
file with the default settings created in the same directory you typed above CLI
command.
Hope this helps.
Just tried both ways and in both ways I got generated .env
file:
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
If you have trouble viewing the .env file or it is not showing up in the project just do this: ls -a
.
This allows to see the hidden files in Linux. You can also open the folder with Visual Studio Code and you will see the files and be able to modify them.
If the .env
a file is missing, then there is another way to generate a .env file
You can download env.example, rename it to .env
and edit it. Just set up correct DB credentials etc.
Don't forget to When you use the php artisan key:generate
it will generate the new key to your .env
file
in console (cmd), go to app root path and execute:
type .env.example > .env
Source: Stackoverflow.com