I have UAT and Production websites.
My UAT website sometimes connecting to main database although I changed the database connection in .env
file.
After changing connection, I also run the following Artisan commands:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
But it is not working.
Here is my .env
file.
APP_NAME=my_app_name
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db_uat
DB_USERNAME=
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
Here is my config\database.php
file.
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', ''),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db_uat'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
],
My Answer:
'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db_uat'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
In your .env file, make sure you have the correct values for DB_HOST, DB_DATABASE, DB_USERNAME, and DB_PASSWORD for your UAT database. If you have made changes to the .env file and run the artisan commands mentioned, but the UAT website is still connecting to the main database, try restarting your web server or clearing your browser cache. If the issue persists, check for any caching mechanisms in your application that may be causing the old database connection to be used.
Rate this post
5 of 5 based on 8747 votesComments