AbdulBazith's avatar

Laravel .env file not changing the database

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

0 likes
5 replies
tiagotavares's avatar

Hi,

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

Hope this helps

4 likes
AbdulBazith's avatar

@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?

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

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.

1 like
jlrdw's avatar

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

1 like

Please or to participate in this conversation.