<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="➜  src  git clone git://github.com/symfony/symfony.git
Cloning into 'symfony'...
remote: Counting objects: 144068, done.
remote: Compressing objects: 100% (44515/44515), done.
remote: Total 144068 (delta 91155), reused 135518 (delta 83912)
Receiving objects: 100% (144068/144068), 22.84 MiB | 837 KiB/s, done.
Resolving deltas: 100% (91155/91155), done.

➜  src  cd symfony 

➜  symfony git:(master) composer install  
Installing dependencies
  - Installing doctrine/common (2.3.x-dev)
    Cloning 605b1b8b5a7bc8daf9111fb35483e5708e30de35

  - Installing twig/twig (dev-master)
    Cloning 459720ff3b74ee0c0d159277c6f2f5df89d8a4f6

Writing lock file
Generating autoload files

➜  symfony git:(master) phpunit           

Warning: require_once(/usr/local/src/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php): failed to open stream: No such file or directory in /usr/local/src/symfony/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php on line 59

Call Stack:
    0.0002     274896   1. {main}() /usr/local/src/phpunit/phpunit.php:0
    0.0254    2845976   2. PHPUnit_TextUI_Command::main() /usr/local/src/phpunit/phpunit.php:46
    0.0254    2846568   3. PHPUnit_TextUI_Command-&gt;run() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:130
    0.0254    2847120   4. PHPUnit_TextUI_Command-&gt;handleArguments() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:139
    0.0312    3242512   5. PHPUnit_TextUI_Command-&gt;handleBootstrap() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:615
    0.0314    3252840   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:787
    0.0314    3253224   7. PHPUnit_Util_Fileloader::load() /usr/local/src/phpunit/PHPUnit/Util/Fileloader.php:77
    0.0315    3260656   8. include_once('/usr/local/src/symfony/autoload.php.dist') /usr/local/src/phpunit/PHPUnit/Util/Fileloader.php:93
    0.0330    3385496   9. Doctrine\Common\Annotations\AnnotationRegistry::registerFile() /usr/local/src/symfony/autoload.php.dist:17"><pre class="notranslate"><code class="notranslate">➜  src  git clone git://github.com/symfony/symfony.git
Cloning into 'symfony'...
remote: Counting objects: 144068, done.
remote: Compressing objects: 100% (44515/44515), done.
remote: Total 144068 (delta 91155), reused 135518 (delta 83912)
Receiving objects: 100% (144068/144068), 22.84 MiB | 837 KiB/s, done.
Resolving deltas: 100% (91155/91155), done.

➜  src  cd symfony 

➜  symfony git:(master) composer install  
Installing dependencies
  - Installing doctrine/common (2.3.x-dev)
    Cloning 605b1b8b5a7bc8daf9111fb35483e5708e30de35

  - Installing twig/twig (dev-master)
    Cloning 459720ff3b74ee0c0d159277c6f2f5df89d8a4f6

Writing lock file
Generating autoload files

➜  symfony git:(master) phpunit           

Warning: require_once(/usr/local/src/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php): failed to open stream: No such file or directory in /usr/local/src/symfony/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php on line 59

Call Stack:
    0.0002     274896   1. {main}() /usr/local/src/phpunit/phpunit.php:0
    0.0254    2845976   2. PHPUnit_TextUI_Command::main() /usr/local/src/phpunit/phpunit.php:46
    0.0254    2846568   3. PHPUnit_TextUI_Command-&gt;run() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:130
    0.0254    2847120   4. PHPUnit_TextUI_Command-&gt;handleArguments() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:139
    0.0312    3242512   5. PHPUnit_TextUI_Command-&gt;handleBootstrap() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:615
    0.0314    3252840   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/local/src/phpunit/PHPUnit/TextUI/Command.php:787
    0.0314    3253224   7. PHPUnit_Util_Fileloader::load() /usr/local/src/phpunit/PHPUnit/Util/Fileloader.php:77
    0.0315    3260656   8. include_once('/usr/local/src/symfony/autoload.php.dist') /usr/local/src/phpunit/PHPUnit/Util/Fileloader.php:93
    0.0330    3385496   9. Doctrine\Common\Annotations\AnnotationRegistry::registerFile() /usr/local/src/symfony/autoload.php.dist:17
</code></pre></div>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>4.0.8</td>
</tr>
</tbody>
</table>
<p dir="auto">Hi,</p>
<p dir="auto">I'd like to jump on the Symfony 4 bandwagon but I'm usure how a Command can use env vars when it's part of a website project.</p>
<p dir="auto">The symfony documentation recommends to define the necessary env vars <a href="https://symfony.com/doc/current/configuration/external_parameters.html#configuration-env-var-in-prod" rel="nofollow">in the web server</a>. In my case, that would be in the virtual host configuration file for apache2. So far,</p>
<p dir="auto">For example, let's say i define a <code class="notranslate">DATABASE_URL</code> var that is used by Doctrine to connect to my database. This works fine for my app when I access the website.</p>
<p dir="auto">Let's say I need a Command to be executed periodically (using <code class="notranslate">cron</code> the server) to compute and save some new data, based on the data currently stored in the database. My Command would need to access the database but it won't be launched from the web server, so the virtual host config file won't set the environment variables.</p>
<p dir="auto">I could put everything I need in an <code class="notranslate">.env</code> file, install <code class="notranslate">symfony/dotenv</code> in prod but :</p>
<ul dir="auto">
<li>that would go against the good practice recommended by Symfony :
<blockquote>
<p dir="auto">In production, it is recommended to configure the environment variables in your web server configuration.<br>
<a href="https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments" rel="nofollow">https://symfony.com/doc/current/configuration/environments.html#executing-an-application-in-different-environments</a></p>
</blockquote>
</li>
<li>I would have duplicated the same content across 2 files, which is a pain to maintain</li>
</ul>
<p dir="auto"><strong>Is there a way to keep within the best practices and not duplicate my config ?</strong></p>