4

This frequently happens in my Laravel 5 app where sometimes .env variables cannot be read.

I have the following in my .env file:

STRIPE_SECRET=sk_test_mykey
STRIPE_KEY=pk_test_mykey

After clearing all the cache using all of these commands I still cannot access the STRIPE_SECRET variable:

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

I have tried in my controller using env('STRIPE_SECRET') and have also tried in tinker:

enter image description here

Any one know why this happens?

4
  • are you running php artisan serve? Commented Jun 11, 2018 at 8:55
  • Yes I am using that, do I need to restart? Commented Jun 11, 2018 at 8:55
  • Yess you have to restart every time you make changes in your .env Commented Jun 11, 2018 at 8:56
  • I also had to restart my terminal to test the env variables. Commented Jun 11, 2018 at 8:58

3 Answers 3

2

If you are running your server using php artisan serve.

You have to restart your server because built in server cache all the .env variables in its memory.

Sign up to request clarification or add additional context in comments.

Comments

2

Just run this: php artisan config:clear

1 Comment

This might answer a similar question and perhaps it is useful to people landing on this page, but the OP clearly stated that the cache had been cleared and it was established early that the development server was being used. Restarting the development server is the solution.
0

have you restarted your artisan server if not restart it and if you are using a virtual machine like vagrant try to get out of your machine and reload it using

vagrant reload

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.