I'm trying to change the environment in my app from local to production. I've modified the .env file but whenever I run a query it's not using the config I have in config/database.php, or the database settings in .env, but the default homestead @ localhost. How can I change the environment to production?
3 Answers
In Laravel 5 the .env file is the file you need to edit. The DB values are stored there.
This file should be in .gitignore as there is a .env.example
change the
APP_ENV=production
APP_DEBUG=false
APP_KEY=yourkey
DB_HOST=tost
DB_DATABASE=db
DB_USERNAME=un
DB_PASSWORD=pwd
CACHE_DRIVER=file
SESSION_DRIVER=file
to look like that on your production environment as it no longer uses the values in config/database
files in that config dir should keep config that is the same across environments
7 Comments
Styphon
OK, I've done that yet it's not using the details in that file. It's still trying to use homestead @ localhost to connect to the database.
ConfusedDevelopment
If you run
php artisan env in your project directory, what does it print out ?Styphon
Artisan detects the environment file fine, and I'm able to use migrate to create tables. However when I try to create an account using the default page I get the error that the system couldn't connect to the database using "homestead @ localhost".
ConfusedDevelopment
Hmm, that's a little strange. In your config directory, in the databases file, are there any values set there to do with homestead ? perhaps could you do a recursive grep for 'homestead' in your project directory ?
Styphon
OK, turns out that all I needed to do was after changing the .env file I had to restart
artisan serve... I hadn't tried running it since the problem occurred and it just came to me that it might have been cached until the server restarted. |