1

Has anyone had issues with Craft parsing a .env on Windows Server? Dotenv is throwing an exception (FileException - invalid name) when parsing the first line of my .env, which is just a comment. I can remove that line and then i complains about the next line.

My .env simple starts with:

# The environment Craft is currently running in (dev, staging, production, etc.)
ENVIRONMENT=dev

basically, Dotenv/Parser/isValidName's Regex call is failing.

Full Stack...

Fatal error: Uncaught Dotenv\Exception\InvalidFileException: Failed to parse dotenv file due to an invalid name. Failed at [ENVIRONMENT]. in C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Parser.php:74 

Stack trace: 
#0 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Parser.php(30): Dotenv\Parser::parseName() 

#1 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Loader.php(169): Dotenv\Parser::parse()

#2 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Loader.php(107): Dotenv\Loader->processEntries()

#3 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Loader.php(91): Dotenv\Loader->loadDirect()

#4 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Dotenv.php(123): Dotenv\Loader->load()

#5 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Dotenv.php(80): Dotenv\Dotenv->loadData()

#6 in C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Parser.php on line 74
  • Huh... use dotenv on Windows all the time (granted not Windows Server, but I'd be surprised if that was the issue). Can you edit the question and share the full stack trace leading up to that error? – Brad Bell Nov 16 '20 at 1:51
  • Could it possibly be something like text encoding of the .env file? Or PHP config? – carbonjoetunis Nov 16 '20 at 14:24
  • Encoding is a possibility - maybe try opening it up in Notepad++, ensure the encoding is UTF-8 and resaving it. You could also go to View->Show Symnbol->Show All Characters to make sure there's no hidden whitespace characters in there screwing things up. – Brad Bell Nov 16 '20 at 21:48
  • Yeah, so I owned it in VSCode and it was UTF8 + bass or something. Created a new file as just UTF8, but same problem. I did notice in the logs, where a request comes through and the environment variables are printed out, there is a special/weird (?) character right at the beginning of the file. I'll try to remove it, but I don't see it in VS Code or Notepad. Thanks for the help. – carbonjoetunis Nov 17 '20 at 1:13
  • Turns out it WAS a file encoding issue. It was UTF BOM (?), and had a weird hidden character right at the beginning of the file. I was able to open the file up in Notepad++ (Thanks Brad) and was able to convert the file to "normal" UTF8. – carbonjoetunis Nov 18 '20 at 1:39
1

Turns out it WAS a file encoding issue. It was UTF BOM (?), and had a weird hidden character right at the beginning of the file. I was able to open the file up in Notepad++ (Thanks Brad) and was able to convert the file to "normal" UTF8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.