Answers.Body: <p>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 &quot;normal&quot; UTF8.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-18T13:15:44.280Z
Answers.LastActivityDate: 2020-11-18T13:15:44.280Z
Answers.UserDisplayName: carbonjoetunis
Body: <p>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.</p>
  <p>My .env simple starts with:</p>
  <pre><code># The environment Craft is currently running in (dev, staging, production, etc.)
  ENVIRONMENT=dev
  </code></pre>
  <p>basically, Dotenv/Parser/isValidName's Regex call is failing.</p>
  <p>Full Stack...</p>
  <pre><code>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-&gt;processEntries()
  
  #3 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Loader.php(91): Dotenv\Loader-&gt;loadDirect()
  
  #4 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Dotenv.php(123): Dotenv\Loader-&gt;load()
  
  #5 C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Dotenv.php(80): Dotenv\Dotenv-&gt;loadData()
  
  #6 in C:\WebRoot\WebApplications\advantage-rebate-portal-v4.0\vendor\vlucas\phpdotenv\src\Parser.php on line 74
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-16T01:51:55.300Z
Comments.Text: 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?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-16T14:24:56.180Z
Comments.Text: Could it possibly be something like text encoding of the .env file? Or PHP config?
Comments.UserDisplayName: carbonjoetunis
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-16T21:48:27.993Z
Comments.Text: 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.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-17T01:13:16.533Z
Comments.Text: 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.
Comments.UserDisplayName: carbonjoetunis
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-18T01:39:16.120Z
Comments.Text: 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.
Comments.UserDisplayName: carbonjoetunis
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-11-18T02:14:09.470Z
Comments.Text: Glad you got it sorted! Want to add that as an official answer in case it ends up helping someone in the future?
Comments.UserDisplayName: Brad Bell
Tags: <windows><env>
Title: .env parsing error on Windows server
ThreadText: # .env parsing error on Windows server
  
  (Asked by: username_0 on 2020-11-15)
  
  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
  
  ```
  
  **Tags:** windows, env
  
  > **Comments:**
  > **username_1**: 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?  
  > **username_0**: Could it possibly be something like text encoding of the .env file? Or PHP config?  
  > **username_1**: 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.  
  > **username_0**: 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.  
  > **username_0**: 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 username_1) and was able to convert the file to "normal" UTF8.  
  > **username_1**: Glad you got it sorted! Want to add that as an official answer in case it ends up helping someone in the future?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-11-18. Score: 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 username_1) and was able to convert the file to "normal" UTF8.
  
  
  ---
  
  