Laravel .env file not changing the database

Published 1 week ago by AbdulBazith

Guys I worked with a project name PROJECT1 . I hosted it in an domain in Cpanel. For testing purpose I duplicated the project and renamed it as PROJECT2 in the same domain. Now I changed the DB_DATABASE,DB_USERNAME,DB_PASSWORD in the .env file in the PROJECT2. Now whats my problem is I changed the db name for PROJECT2 but it still works with the old DB. Still it fetched data from the old db how?

the PROJRCT1 is also in the same domain..

Whats the reason for this problem. Do I need to change any other file to change the DB.

Please suggest your ideas

Best Answer (As Selected By AbdulBazith)
Cronix

artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recache them. That's why it still works after deleting .env.

https://laravel.com/docs/5.6/configuration#configuration-caching

If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.

tiagotavares

Hi,

Try running: php artisan config:cache to reload the new values from the .env file.

Hope this helps

AbdulBazith

@tiagotavares yes your comment helps in local but my project is in live hostgator domain.

How should i use command prompt in live server. where i should give the php artisan config:cache line in live server

even i deleted the .env file still it works how?

Cronix
Cronix
1 week ago (573,640 XP)

artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recache them. That's why it still works after deleting .env.

https://laravel.com/docs/5.6/configuration#configuration-caching

If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.

jlrdw
jlrdw
1 week ago (227,770 XP)

Just curious do you have laravel installed correctly if you don't mind what is your complete site URL?

AbdulBazith

@Cronix thank you sooo much it worked...

Please sign in or create an account to participate in this conversation.