How to generate .env file for laravel?

前端 未结 10 1034
不知归路
不知归路 2020-12-24 05:39

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

$laravel new blog

or via composer:



        
相关标签:
10条回答
  • 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.

    0 讨论(0)
  • 2020-12-24 06:11

    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.

    0 讨论(0)
  • 2020-12-24 06:14

    I had this problem of no .env files showing up in the project.

    Turns out the IDE I was using (Netbeans, try not to judge) will show certain types of .hidden files but not all.

    After racking my brains for a bit I checked the file system and found the .env + .env.example files / modified them with a text editor.

    Leaving this answer for the rare situation someones using a dodgy IDE like myself.

    0 讨论(0)
  • 2020-12-24 06:15

    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

    0 讨论(0)
  • 2020-12-24 06:19

    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

    0 讨论(0)
  • 2020-12-24 06:23

    .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.

    0 讨论(0)
提交回复
热议问题