Laravel 5.6 cannot access some .env variables - php

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:
Any one know why this happens?

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.

Just run this: php artisan config:clear

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

Related

Laravel ENV not reload

I use Laravel 6.2 with valet and PHP 7.3.12
The problem is I want to change DB_DATABASE=laravel to DB_DATABASE=something_else in .env file
but it doesn't reload the new .env value at all
I have already tried this command:
php artisan config:clear
php artisan config:cache
but it still doesn't change at all.
I even try to add a new key to .env file and query it in Tinker and the new key doesn't add as well.
After completion of .env edit, You can clear the configuration cache with the following artisan command: php artisan config:cache
Use php artisan key:generate it will generate the new key to your .env file
NOTE: If there is still error then you do not need your restart computer just try this:
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server
OR
If you have used XAMPP then restart your Apache server
I just restart my computer at first it doesn't work then I did
php artisan config:cache and it works now.
whenever you want to change content .env file
run php artisan cache:clear command to get newly added values
Restarting you computer has nothing to do with it.
If you are working on a local environment then please stop your development server by pressing ctrl+c and then restart the application by running php artisan serve.

Laravel 5 config cache issue while accessing app url inside the code

I'm using laravel 5.5. Recently I have disabled ssl for my site. So I just edited .env file and set APP_URL as http://www.example.com instead of https://www.example.com. But when ever I try access url inside my code it returns with https as previously. for eg url('sample_route') returns https://www.example.com/sample_route. I have tried clearing cache and configs through artisan commands. but still getting same result.
You can try command composer dump-autoload too with cache & config clear command.
Have you tried all php artisan commands in clearing caches?
php artisan route:clear
php artisan config:cache
php artisan cache:clear
php artisan view clear

Laravel view [auth.login] not found on server

I have a problem with my project laravel 5.7. I have developed it locally and all is well but once sent to my server online I have this error: view [auth.login] not found.
Ran into the same problem. I noticed three things;
A message while booting homestead about virtualbox guest-tools being out of sync between host and guest. There could be a problem with paths. I fixed that issue with the help of this here
The Laravel view [auth.login] not found on server page displayed the path of the host machine and not of the vagrant-guest.
bootstrap/cache/config.php also displayed paths from the host and not the guest.
Renaming/deleting (or artisan cache:clear) the config.php only gave errors (Laravel Error “Unable to load the ”app“ configuration file”).
I fixed the issue by correcting the paths in config.php manually to the correct path in vagrant.
Run following commands on your server.
it might solve your problem.
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan route:cache
php artisan optimize
or
composer dump-autoload -o
if you are in develop mode you can run:
php artisan config:clear
or if you are in product mode you can run:
php artisan config:cache
notice: when you use second, config clear and cache again and you force to repeat command for other changes.

How can I refresh the .env file in Laravel if there's no root access?

I am on a shared hosting. I am not the developer but I just changed a value in the .env file but the change is not reflecting on the main site. I even tried by opening http://siteurl.com/clear-cache(it says cache cleared) but it didn't work. How can I refresh it without root access? I can hardcode the value for now as a temporary hack but I want to make it work via the .env file.
In order to clear cache of config in Laravel 5
php artisan config:clear
php artisan config:cache
php artisan cache:clear
php artisan route:cache
php artisan optimize
with those command you will clear all cache and go on

Cannot delete Laravel Application cache from deployment script

I am trying to setup a deployment script for my Laravel 5 app to use with CodeShip but I am having issues with clearing the application cache during the deployment.
By running
php artisan cache:clear
it does not give any errors and says the cache has been cleared but it hasnt, then when I ssh into the box and try to delete the cache manually it says permission is denied, so I need to use sudo which is not ideal as Id like to have this all to run without my intervention. I know this is a permissions issue but I cannot work out a way around it.
Is there a way I can do this or maybe a slightly different method?
You shouldn't delete cache manually. Try to run these commands:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear
composer dump-autoload
Try php artisan config:cache
This will do it all for you.
Hope this helps!

Categories