Laravel 5.3 - env() always returns null











up vote
12
down vote

favorite
4












I try to find out why my env() helper always returns null. This causes trouble especially in app.php file, where are env() helpers widely used by default. Perhaps any mysterious server setting?



My env file:



APP_ENV=production
APP_KEY=base64:mymagickey=
APP_DEBUG=false
APP_LOG_LEVEL=info
APP_URL=http://www.example.com

etc...


EDIT - I tried following:



php artisan cache:clear
php artisan view:clear
php artisan config:cache


and ofcourse, i am using env helper like this: env('APP_ENV')



But still no success. The wierd part is, that $_ENV php variable contains every single variable from .env file.










share|improve this question




















  • 1




    have you tried to check the values via tinker ? also which version of Laravel 5 you are using ? the latest one is 5.4.17 as I remember, so what is your latest versoin
    – Zaher
    Apr 6 '17 at 11:20















up vote
12
down vote

favorite
4












I try to find out why my env() helper always returns null. This causes trouble especially in app.php file, where are env() helpers widely used by default. Perhaps any mysterious server setting?



My env file:



APP_ENV=production
APP_KEY=base64:mymagickey=
APP_DEBUG=false
APP_LOG_LEVEL=info
APP_URL=http://www.example.com

etc...


EDIT - I tried following:



php artisan cache:clear
php artisan view:clear
php artisan config:cache


and ofcourse, i am using env helper like this: env('APP_ENV')



But still no success. The wierd part is, that $_ENV php variable contains every single variable from .env file.










share|improve this question




















  • 1




    have you tried to check the values via tinker ? also which version of Laravel 5 you are using ? the latest one is 5.4.17 as I remember, so what is your latest versoin
    – Zaher
    Apr 6 '17 at 11:20













up vote
12
down vote

favorite
4









up vote
12
down vote

favorite
4






4





I try to find out why my env() helper always returns null. This causes trouble especially in app.php file, where are env() helpers widely used by default. Perhaps any mysterious server setting?



My env file:



APP_ENV=production
APP_KEY=base64:mymagickey=
APP_DEBUG=false
APP_LOG_LEVEL=info
APP_URL=http://www.example.com

etc...


EDIT - I tried following:



php artisan cache:clear
php artisan view:clear
php artisan config:cache


and ofcourse, i am using env helper like this: env('APP_ENV')



But still no success. The wierd part is, that $_ENV php variable contains every single variable from .env file.










share|improve this question















I try to find out why my env() helper always returns null. This causes trouble especially in app.php file, where are env() helpers widely used by default. Perhaps any mysterious server setting?



My env file:



APP_ENV=production
APP_KEY=base64:mymagickey=
APP_DEBUG=false
APP_LOG_LEVEL=info
APP_URL=http://www.example.com

etc...


EDIT - I tried following:



php artisan cache:clear
php artisan view:clear
php artisan config:cache


and ofcourse, i am using env helper like this: env('APP_ENV')



But still no success. The wierd part is, that $_ENV php variable contains every single variable from .env file.







php laravel-5 environment-variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 6 '17 at 11:43

























asked Apr 6 '17 at 0:27









Fusion

1,12721529




1,12721529








  • 1




    have you tried to check the values via tinker ? also which version of Laravel 5 you are using ? the latest one is 5.4.17 as I remember, so what is your latest versoin
    – Zaher
    Apr 6 '17 at 11:20














  • 1




    have you tried to check the values via tinker ? also which version of Laravel 5 you are using ? the latest one is 5.4.17 as I remember, so what is your latest versoin
    – Zaher
    Apr 6 '17 at 11:20








1




1




have you tried to check the values via tinker ? also which version of Laravel 5 you are using ? the latest one is 5.4.17 as I remember, so what is your latest versoin
– Zaher
Apr 6 '17 at 11:20




have you tried to check the values via tinker ? also which version of Laravel 5 you are using ? the latest one is 5.4.17 as I remember, so what is your latest versoin
– Zaher
Apr 6 '17 at 11:20












6 Answers
6






active

oldest

votes

















up vote
23
down vote













Hope this command will save you




php artisan config:clear







share|improve this answer




























    up vote
    5
    down vote













    Use Config::get('app.env'); instead of env(APP_ENV); because you're going to get the same error eventually and that's not good for a live website.



    If you want to add custom variables from your ENV, go into your config app and find this:



    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services your application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),


    add a new line under "'env' => env('APP_ENV', 'production'),", so for example, it could be the following:



    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services your application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),
    'key' => env('APP_KEY'),


    You can call the "key" variable like this:



    Config::get('app.key');


    Whenever you add a new variable like "key" to the app env, you'll need to use config:cache to reset the cache.






    share|improve this answer





















    • I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
      – Amit Shah
      Sep 17 at 9:44










    • @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
      – Yevgeniy Afanasyev
      Nov 20 at 2:38


















    up vote
    3
    down vote













    It is a ".env" known bug which can be solved with:



    php artisan config:cache





    share|improve this answer

















    • 9




      Some users may need to do php artisan config:clear instead
      – rebirth1078
      Jul 11 '17 at 15:02






    • 5




      Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
      – dacastro4
      Oct 24 '17 at 16:18






    • 2




      php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
      – BRBdot
      Jul 26 at 14:40










    • follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
      – BRBdot
      Jul 26 at 16:33


















    up vote
    0
    down vote



    accepted










    Looks like there was installed old PHP version on server, which is not situable for Laravel's .env package to run properly. When I deployed website into a different server with PHP 7 installed, env() returned values as expected.






    share|improve this answer























    • It is not about php version, it is about deployment scripts, please see my answer for details.
      – Yevgeniy Afanasyev
      Nov 20 at 2:36


















    up vote
    0
    down vote













    env(...) function will not work after you cached the config. (starting from laravel 5.2 till current 5.7)



    The documentation says




    If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.




    So the correct answer would be to




    If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.




    And I quoted it from the same documentation



    But for a quick fix this will do:




    php artisan config:clear




    And now it should be clear why, when you tried config:cache it did not help, even though it clears the config prior to caching.






    share|improve this answer




























      up vote
      0
      down vote













      Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications.
      Here is full explanation:
      https://www.youtube.com/watch?v=Q1ynDMC8UGg



      php artisan config:clear
      php artisan cache:clear
      composer dump-autoload
      php artisan view:clear
      php artisan route:clear





      share|improve this answer























      • the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
        – calin24
        Oct 8 at 7:08










      • I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
        – Learner
        Oct 8 at 7:47






      • 1




        running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
        – calin24
        Oct 8 at 8:46










      • I am glad it worked.
        – Learner
        Oct 8 at 10:01










      • I read your discussion and put my explanation in the separate answer, please check it out.
        – Yevgeniy Afanasyev
        Nov 20 at 2:33













      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43243732%2flaravel-5-3-env-always-returns-null%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      23
      down vote













      Hope this command will save you




      php artisan config:clear







      share|improve this answer

























        up vote
        23
        down vote













        Hope this command will save you




        php artisan config:clear







        share|improve this answer























          up vote
          23
          down vote










          up vote
          23
          down vote









          Hope this command will save you




          php artisan config:clear







          share|improve this answer












          Hope this command will save you




          php artisan config:clear








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 26 at 7:44









          sh6210

          65349




          65349
























              up vote
              5
              down vote













              Use Config::get('app.env'); instead of env(APP_ENV); because you're going to get the same error eventually and that's not good for a live website.



              If you want to add custom variables from your ENV, go into your config app and find this:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),


              add a new line under "'env' => env('APP_ENV', 'production'),", so for example, it could be the following:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),
              'key' => env('APP_KEY'),


              You can call the "key" variable like this:



              Config::get('app.key');


              Whenever you add a new variable like "key" to the app env, you'll need to use config:cache to reset the cache.






              share|improve this answer





















              • I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
                – Amit Shah
                Sep 17 at 9:44










              • @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:38















              up vote
              5
              down vote













              Use Config::get('app.env'); instead of env(APP_ENV); because you're going to get the same error eventually and that's not good for a live website.



              If you want to add custom variables from your ENV, go into your config app and find this:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),


              add a new line under "'env' => env('APP_ENV', 'production'),", so for example, it could be the following:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),
              'key' => env('APP_KEY'),


              You can call the "key" variable like this:



              Config::get('app.key');


              Whenever you add a new variable like "key" to the app env, you'll need to use config:cache to reset the cache.






              share|improve this answer





















              • I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
                – Amit Shah
                Sep 17 at 9:44










              • @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:38













              up vote
              5
              down vote










              up vote
              5
              down vote









              Use Config::get('app.env'); instead of env(APP_ENV); because you're going to get the same error eventually and that's not good for a live website.



              If you want to add custom variables from your ENV, go into your config app and find this:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),


              add a new line under "'env' => env('APP_ENV', 'production'),", so for example, it could be the following:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),
              'key' => env('APP_KEY'),


              You can call the "key" variable like this:



              Config::get('app.key');


              Whenever you add a new variable like "key" to the app env, you'll need to use config:cache to reset the cache.






              share|improve this answer












              Use Config::get('app.env'); instead of env(APP_ENV); because you're going to get the same error eventually and that's not good for a live website.



              If you want to add custom variables from your ENV, go into your config app and find this:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),


              add a new line under "'env' => env('APP_ENV', 'production'),", so for example, it could be the following:



              /*
              |--------------------------------------------------------------------------
              | Application Environment
              |--------------------------------------------------------------------------
              |
              | This value determines the "environment" your application is currently
              | running in. This may determine how you prefer to configure various
              | services your application utilizes. Set this in your ".env" file.
              |
              */

              'env' => env('APP_ENV', 'production'),
              'key' => env('APP_KEY'),


              You can call the "key" variable like this:



              Config::get('app.key');


              Whenever you add a new variable like "key" to the app env, you'll need to use config:cache to reset the cache.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jul 10 '17 at 8:10









              rebirth1078

              12719




              12719












              • I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
                – Amit Shah
                Sep 17 at 9:44










              • @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:38


















              • I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
                – Amit Shah
                Sep 17 at 9:44










              • @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:38
















              I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
              – Amit Shah
              Sep 17 at 9:44




              I am not sure but may be this bug only occurs in windows. but your solution resolved it in windows too. will it work in linux production environment?
              – Amit Shah
              Sep 17 at 9:44












              @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
              – Yevgeniy Afanasyev
              Nov 20 at 2:38




              @AmitShah, it is not a bug, it is a feature. Please check out my answer for details.
              – Yevgeniy Afanasyev
              Nov 20 at 2:38










              up vote
              3
              down vote













              It is a ".env" known bug which can be solved with:



              php artisan config:cache





              share|improve this answer

















              • 9




                Some users may need to do php artisan config:clear instead
                – rebirth1078
                Jul 11 '17 at 15:02






              • 5




                Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
                – dacastro4
                Oct 24 '17 at 16:18






              • 2




                php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
                – BRBdot
                Jul 26 at 14:40










              • follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
                – BRBdot
                Jul 26 at 16:33















              up vote
              3
              down vote













              It is a ".env" known bug which can be solved with:



              php artisan config:cache





              share|improve this answer

















              • 9




                Some users may need to do php artisan config:clear instead
                – rebirth1078
                Jul 11 '17 at 15:02






              • 5




                Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
                – dacastro4
                Oct 24 '17 at 16:18






              • 2




                php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
                – BRBdot
                Jul 26 at 14:40










              • follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
                – BRBdot
                Jul 26 at 16:33













              up vote
              3
              down vote










              up vote
              3
              down vote









              It is a ".env" known bug which can be solved with:



              php artisan config:cache





              share|improve this answer












              It is a ".env" known bug which can be solved with:



              php artisan config:cache






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Apr 6 '17 at 0:31









              vpdeva

              144110




              144110








              • 9




                Some users may need to do php artisan config:clear instead
                – rebirth1078
                Jul 11 '17 at 15:02






              • 5




                Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
                – dacastro4
                Oct 24 '17 at 16:18






              • 2




                php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
                – BRBdot
                Jul 26 at 14:40










              • follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
                – BRBdot
                Jul 26 at 16:33














              • 9




                Some users may need to do php artisan config:clear instead
                – rebirth1078
                Jul 11 '17 at 15:02






              • 5




                Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
                – dacastro4
                Oct 24 '17 at 16:18






              • 2




                php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
                – BRBdot
                Jul 26 at 14:40










              • follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
                – BRBdot
                Jul 26 at 16:33








              9




              9




              Some users may need to do php artisan config:clear instead
              – rebirth1078
              Jul 11 '17 at 15:02




              Some users may need to do php artisan config:clear instead
              – rebirth1078
              Jul 11 '17 at 15:02




              5




              5




              Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
              – dacastro4
              Oct 24 '17 at 16:18




              Laravel 5.5 I had to run 'php artisan config:clear'. Thanks
              – dacastro4
              Oct 24 '17 at 16:18




              2




              2




              php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
              – BRBdot
              Jul 26 at 14:40




              php artisan config:cache is the reason why env() values are null. If you wish to cache your config and env vars then you shouldn't use env() anywhere else except config files because once cached env() will always return null. Although now I am also seeing config() and Config::get() helper return null after caching which is weird too.
              – BRBdot
              Jul 26 at 14:40












              follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
              – BRBdot
              Jul 26 at 16:33




              follow up to above - ...So thats when you should realize that config() helper cannot directly access values in .env either. You will need to create or use existing config/<insert config file name>.php config file and create your config entry from .env and then use that mapped value.
              – BRBdot
              Jul 26 at 16:33










              up vote
              0
              down vote



              accepted










              Looks like there was installed old PHP version on server, which is not situable for Laravel's .env package to run properly. When I deployed website into a different server with PHP 7 installed, env() returned values as expected.






              share|improve this answer























              • It is not about php version, it is about deployment scripts, please see my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:36















              up vote
              0
              down vote



              accepted










              Looks like there was installed old PHP version on server, which is not situable for Laravel's .env package to run properly. When I deployed website into a different server with PHP 7 installed, env() returned values as expected.






              share|improve this answer























              • It is not about php version, it is about deployment scripts, please see my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:36













              up vote
              0
              down vote



              accepted







              up vote
              0
              down vote



              accepted






              Looks like there was installed old PHP version on server, which is not situable for Laravel's .env package to run properly. When I deployed website into a different server with PHP 7 installed, env() returned values as expected.






              share|improve this answer














              Looks like there was installed old PHP version on server, which is not situable for Laravel's .env package to run properly. When I deployed website into a different server with PHP 7 installed, env() returned values as expected.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 15 at 12:07

























              answered Apr 12 '17 at 15:17









              Fusion

              1,12721529




              1,12721529












              • It is not about php version, it is about deployment scripts, please see my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:36


















              • It is not about php version, it is about deployment scripts, please see my answer for details.
                – Yevgeniy Afanasyev
                Nov 20 at 2:36
















              It is not about php version, it is about deployment scripts, please see my answer for details.
              – Yevgeniy Afanasyev
              Nov 20 at 2:36




              It is not about php version, it is about deployment scripts, please see my answer for details.
              – Yevgeniy Afanasyev
              Nov 20 at 2:36










              up vote
              0
              down vote













              env(...) function will not work after you cached the config. (starting from laravel 5.2 till current 5.7)



              The documentation says




              If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.




              So the correct answer would be to




              If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.




              And I quoted it from the same documentation



              But for a quick fix this will do:




              php artisan config:clear




              And now it should be clear why, when you tried config:cache it did not help, even though it clears the config prior to caching.






              share|improve this answer

























                up vote
                0
                down vote













                env(...) function will not work after you cached the config. (starting from laravel 5.2 till current 5.7)



                The documentation says




                If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.




                So the correct answer would be to




                If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.




                And I quoted it from the same documentation



                But for a quick fix this will do:




                php artisan config:clear




                And now it should be clear why, when you tried config:cache it did not help, even though it clears the config prior to caching.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  env(...) function will not work after you cached the config. (starting from laravel 5.2 till current 5.7)



                  The documentation says




                  If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.




                  So the correct answer would be to




                  If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.




                  And I quoted it from the same documentation



                  But for a quick fix this will do:




                  php artisan config:clear




                  And now it should be clear why, when you tried config:cache it did not help, even though it clears the config prior to caching.






                  share|improve this answer












                  env(...) function will not work after you cached the config. (starting from laravel 5.2 till current 5.7)



                  The documentation says




                  If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.




                  So the correct answer would be to




                  If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.




                  And I quoted it from the same documentation



                  But for a quick fix this will do:




                  php artisan config:clear




                  And now it should be clear why, when you tried config:cache it did not help, even though it clears the config prior to caching.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 2:32









                  Yevgeniy Afanasyev

                  7,63544264




                  7,63544264






















                      up vote
                      0
                      down vote













                      Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications.
                      Here is full explanation:
                      https://www.youtube.com/watch?v=Q1ynDMC8UGg



                      php artisan config:clear
                      php artisan cache:clear
                      composer dump-autoload
                      php artisan view:clear
                      php artisan route:clear





                      share|improve this answer























                      • the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
                        – calin24
                        Oct 8 at 7:08










                      • I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
                        – Learner
                        Oct 8 at 7:47






                      • 1




                        running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
                        – calin24
                        Oct 8 at 8:46










                      • I am glad it worked.
                        – Learner
                        Oct 8 at 10:01










                      • I read your discussion and put my explanation in the separate answer, please check it out.
                        – Yevgeniy Afanasyev
                        Nov 20 at 2:33

















                      up vote
                      0
                      down vote













                      Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications.
                      Here is full explanation:
                      https://www.youtube.com/watch?v=Q1ynDMC8UGg



                      php artisan config:clear
                      php artisan cache:clear
                      composer dump-autoload
                      php artisan view:clear
                      php artisan route:clear





                      share|improve this answer























                      • the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
                        – calin24
                        Oct 8 at 7:08










                      • I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
                        – Learner
                        Oct 8 at 7:47






                      • 1




                        running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
                        – calin24
                        Oct 8 at 8:46










                      • I am glad it worked.
                        – Learner
                        Oct 8 at 10:01










                      • I read your discussion and put my explanation in the separate answer, please check it out.
                        – Yevgeniy Afanasyev
                        Nov 20 at 2:33















                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications.
                      Here is full explanation:
                      https://www.youtube.com/watch?v=Q1ynDMC8UGg



                      php artisan config:clear
                      php artisan cache:clear
                      composer dump-autoload
                      php artisan view:clear
                      php artisan route:clear





                      share|improve this answer














                      Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications.
                      Here is full explanation:
                      https://www.youtube.com/watch?v=Q1ynDMC8UGg



                      php artisan config:clear
                      php artisan cache:clear
                      composer dump-autoload
                      php artisan view:clear
                      php artisan route:clear






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 2 days ago

























                      answered Apr 6 '17 at 5:21









                      Learner

                      3,35611432




                      3,35611432












                      • the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
                        – calin24
                        Oct 8 at 7:08










                      • I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
                        – Learner
                        Oct 8 at 7:47






                      • 1




                        running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
                        – calin24
                        Oct 8 at 8:46










                      • I am glad it worked.
                        – Learner
                        Oct 8 at 10:01










                      • I read your discussion and put my explanation in the separate answer, please check it out.
                        – Yevgeniy Afanasyev
                        Nov 20 at 2:33




















                      • the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
                        – calin24
                        Oct 8 at 7:08










                      • I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
                        – Learner
                        Oct 8 at 7:47






                      • 1




                        running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
                        – calin24
                        Oct 8 at 8:46










                      • I am glad it worked.
                        – Learner
                        Oct 8 at 10:01










                      • I read your discussion and put my explanation in the separate answer, please check it out.
                        – Yevgeniy Afanasyev
                        Nov 20 at 2:33


















                      the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
                      – calin24
                      Oct 8 at 7:08




                      the same problem here....not working env(). I have tried remove cache, composer dump-autoload....etc. I am using laravel 5.5.44 and I have to call the config from .env file with Config::get()
                      – calin24
                      Oct 8 at 7:08












                      I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
                      – Learner
                      Oct 8 at 7:47




                      I have listed all commands at one place you need to run in order to eliminate any kind of cache issue with env file or config etc. Here is the thread: stackoverflow.com/a/43041479/6935763 Please run all of them and let me know if it still doesn't work.
                      – Learner
                      Oct 8 at 7:47




                      1




                      1




                      running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
                      – calin24
                      Oct 8 at 8:46




                      running only php artisan config:cache does not work. After i run php artisan config:clear it works. Now I can use again env($key). Thx @Learner
                      – calin24
                      Oct 8 at 8:46












                      I am glad it worked.
                      – Learner
                      Oct 8 at 10:01




                      I am glad it worked.
                      – Learner
                      Oct 8 at 10:01












                      I read your discussion and put my explanation in the separate answer, please check it out.
                      – Yevgeniy Afanasyev
                      Nov 20 at 2:33






                      I read your discussion and put my explanation in the separate answer, please check it out.
                      – Yevgeniy Afanasyev
                      Nov 20 at 2:33




















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43243732%2flaravel-5-3-env-always-returns-null%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen