1

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 3

1

Put the following line into your boostrap/app.php

  $app->loadEnvironmentFrom('.local.env');

you can change the file name here ('.local.env') what environment file need to run

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

Comments

0

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

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.
If you run php artisan env in your project directory, what does it print out ?
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".
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 ?
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.
|
0

As per my comment all I needed to do was restart the server, in my case artisan serve. It only loads the environment when starting, so any changes don't take effect whilst it's running.

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.