23

This problem only happens with Laravel 5.8 on my shared hosting.

It is working fine in my shared hosting with Laravel 5.7.

It is working fine in my local environment with Laravel 5.8.

the problem is:

every time I run php artisan commands (on my shared hosting with Laravel 5.8 only) I got this error

The environment file is invalid! Failed to parse dotenv file due to an invalid name.

Failed at [APP_NAME].

my .env first line is : APP_NAME=rased

Also my site after updating to Laravel 5.8 is becoming a white blank page!

Community
  • 1
  • 1
Abdulaziz Tayyar
  • 464
  • 1
  • 4
  • 11

13 Answers13

36

This is a general error related to parsing the .env file. You'll see this is indicated in the error e.g.

The environment file is invalid!
Failed to parse dotenv file due to unexpected whitespace. 
Failed at [This will fail].

In this example it was caused by having unescaped whitespace in the APP_NAME field i.e.

APP_NAME=This will fail

To fix, escape with quotes e.g.

APP_NAME="This is better"
Praj Basnet
  • 361
  • 3
  • 3
15

This is general Error when we change our app name. To remove this error just do this.

APP_NAME=My Project Name 

to this

APP_NAME="My Project Name"

You just need to add "" course around name. Thanks

8

I found the cause of this problem.

It was because of line separator in .env file !

It must be CRLF not LF

My .env file was LF

see the screenshot to understand the solution

Abdulaziz Tayyar
  • 464
  • 1
  • 4
  • 11
6

I received a similar error while upgrading from Laravel 5.5 to Laravel 5.8.

The environment file is invalid! Failed to parse dotenv file due to an invalid name. Failed at [//APP_ENV].

5.5 would accept C style comments on APP_ENV:

// env file setup for production environment
//APP_ENV = production
//APP_DEBUG = false
// env file setup for local environment
APP_ENV = local
APP_DEBUG = true

While 5.8 will not. # works for comments:

# env file setup for production environment
#APP_ENV = production
#APP_DEBUG = false
# env file setup for local environment
APP_ENV=local
APP_DEBUG=true

I had tried removing the spaces as a brand new 5.8 application installs without spaces in these definitions. That didn't fix it.

Curiously I still have C style comments other places in the file, so only for APP_ENV?

Paul
  • 311
  • 4
  • 8
4

I changed the encoding of .env and it was solved.

UFT-8 without BOM

Thanks

kenyo
  • 41
  • 1
2

I had exactly the same problem, but a different solution. CRLF made no difference.

This was driving me nuts, and I read somewhere that C style comments were no longer supported. My env file didn't contain any, but in desperation I added the following line to the top of the file:

# getting tiresome.

I don't think the wording is important, but the key thing was there was a comment.

After that, it worked. I don't know why, but it did.

Fast forward a few months, and the problem returned the next time I have to upgrade Laravel. This was kind of weird as the file was the same. This time I had to make sure I saved the file as UTF-8 without BOM.

Relaxing In Cyprus
  • 1,976
  • 19
  • 25
2

I recently ran into this same problem on my app for Laravel 6.12.0.

I was able to resolve this issue by adding a blank new line/space at the top of the .env file.

Example .env file:

    [add a new line here]
    APP_NAME=Laravel
    APP_ENV=local
    APP_KEY=
    APP_DEBUG=true
    APP_URL=http://localhost

    LOG_CHANNEL=stack

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=laravel
    DB_USERNAME=root
    DB_PASSWORD=

    BROADCAST_DRIVER=log
    CACHE_DRIVER=file
    QUEUE_CONNECTION=sync
    SESSION_DRIVER=file
    SESSION_LIFETIME=120

    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null
    MAIL_FROM_ADDRESS=null
    MAIL_FROM_NAME="${APP_NAME}"

    AWS_ACCESS_KEY_ID=
    AWS_SECRET_ACCESS_KEY=
    AWS_DEFAULT_REGION=us-east-1
    AWS_BUCKET=

    PUSHER_APP_ID=
    PUSHER_APP_KEY=
    PUSHER_APP_SECRET=
    PUSHER_APP_CLUSTER=mt1

    MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
    MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
levi
  • 1,566
  • 3
  • 21
  • 37
1

I have added course "" around the DB_DATABASE path.

enter image description here

Mohit Tiwari
  • 165
  • 2
  • 6
0

MAIL_FROM_NAME=Account confirmation

i was just making spaces between the two words Just try to avoid it like : Account_confirmation

MAIL_FROM_NAME=Account_confirmation (correct)

0

In my case, I had an extra line that shouldn't be there.

Header set X-Frame-Options SAMEORIGIN Removed this and IT WORKED

Digvijay
  • 7,836
  • 3
  • 32
  • 53
0

I discover that if you declare the APP_NAME in quotes in the .env file, It will allow spaces in the app name but make sure you restart the server using the command (php artisan serve) For e.g: APP_NAME='Laravel Login'

That works for me.

0

delete the .env file and recreate another with the same content

-1

In case anybody else gets here and hasn't solved their problem. I came across this issue and found that it was due to using a hyphen to separate the environment variable name.

NOM-OPEN="2020/01/24"

This was okay up to Laravel 5.7 but fell over for 5.8. To solve it change the hyphen to an underscore.

NOM_OPEN="2020/01/24"

Don't forget to update all references to the variable!