Answers.Body: <p>If that is really all that you're doing, and you have no other integration with Craft, you can parse the .env however you like. Craft uses <a href="https://github.com/vlucas/phpdotenv" rel="nofollow noreferrer">vlucas/phpdotenv</a> internally so that library is already in your vendor directory. You should be able to pick that up after including Composer's autoloader.</p>
  <p>If however you have any kind if integration with Craft, look at web/index.php and see what's going on in terms of bootstrapping there, copying the parts necessary for your application.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-17T09:09:07.070Z
Answers.Text: I have also update my general.php to include additional environment settings.  But I'm not able to access below
  
  Craft::$app->getConfig()->getGeneral()
Answers.UserDisplayName: Deepak Kale
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-17T09:59:37.853Z
Answers.Text: Where are you calling `Craft::$app->getConfig()->getGeneral()` from, though?
Answers.UserDisplayName: Wallace
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-17T07:52:04.430Z
Answers.LastActivityDate: 2021-05-17T07:52:04.430Z
Answers.UserDisplayName: Wallace
Body: <ul>
  <li>Craft Version 3.2</li>
  <li>PHP Version 7.2</li>
  </ul>
  <p>Below is my folder structure:</p>
  <pre><code>Root
    - Other Craft Folder
    - Web
       - Services
           - Db.php
       - env file
  </code></pre>
  <p>I want to read the connection string of the SQL SERVER from the env file.</p>
  <p>Things I have already tried:</p>
  <ol>
  <li><code>App::env</code></li>
  <li><code>require_once 'C:\wamp64\www\craftApp\vendor\autoload.php'; use craft\helpers\App;</code></li>
  </ol>
  <pre class="lang-php prettyprint-override"><code>print_r(Craft::parseEnv('$sqlServerName')); // Throws Error
  </code></pre>
  <p>But it doesn't work.</p>
  
Tags: <craft3><php><env>
Title: Access env variables in custom php files
ThreadText: # Access env variables in custom php files
  
  (Asked by: username_0 on 2021-05-17)
  
  * Craft Version 3.2
  * PHP Version 7.2
  
  Below is my folder structure:
  
  ```
  Root
    - Other Craft Folder
    - Web
       - Services
           - Db.php
       - env file
  
  ```
  
  I want to read the connection string of the SQL SERVER from the env file.
  
  Things I have already tried:
  
  1. `App::env`
  2. `require_once 'C:\wamp64\www\craftApp\vendor\autoload.php'; use craft\helpers\App;`
  
  ```php
  print_r(Craft::parseEnv('$sqlServerName')); // Throws Error
  
  ```
  
  But it doesn't work.
  
  **Tags:** craft3, php, env
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-05-17. Score: 1
  
  If that is really all that you're doing, and you have no other integration with Craft, you can parse the .env however you like. Craft uses [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv) internally so that library is already in your vendor directory. You should be able to pick that up after including Composer's autoloader.
  
  If however you have any kind if integration with Craft, look at web/index.php and see what's going on in terms of bootstrapping there, copying the parts necessary for your application.
  
  > **Comments:**
  > **username_0**: I have also update my general.php to include additional environment settings.  But I'm not able to access below  Craft::$app->getConfig()->getGeneral()  
  > **username_1**: Where are you calling `Craft::$app->getConfig()->getGeneral()` from, though?  
  
  ---
  
  