0

I'm trying to publish my Laravel 5.8 app on production hosting. I've uploaded the files and have made the changes in .env file. But still while accessing my application., it throws error:

Access denied for user 'root'@'127.0.0.1' (using password: NO)

Below is my .env file:

DB_CONNECTION=mysql
DB_HOST= ip
DB_PORT=3306
DB_DATABASE=secret
DB_USERNAME='secret'
DB_PASSWORD='secret'

I have also made changes in database.php:

'users' => [
    'driver' => 'mysql',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', 'secret'),
    'port' => env('DB_PORT', '3306'),
    'database' => env(‘DB_DATABASE', 'secret'),
    'username' => env('DB_USERNAME', 'secret'),
    'password' => env('DB_PASSNORD', 'secret'),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'prefix_indexes' => true,
    'strict' => true,
    'engine' => null,
    'options' => extension_loaded('pdo_mysql') ? array_filter([
        PDO: :I'IYSQL_ATTR_SSL_CA => env( 'MYSQL_ATTR_SS L_CA' ),
    ]) : [],
},
2
  • Use localhost instead of 127.0.0.1 then comment results. Commented Nov 19, 2019 at 11:39
  • run php artisan config:clear Commented Nov 19, 2019 at 11:42

2 Answers 2

1

Try.

php artisan config:cache

then

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret   //enter your right databse name
DB_USERNAME=secret  //please check your username
DB_PASSWORD=secret  //please check your password

or

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret  //enter your right databse name
DB_USERNAME=root     //please check your username
DB_PASSWORD=enter your correct password //please check your password

change your databse.php

'users' => [
    'driver' => 'mysql',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env(‘DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSNORD', ''),
    '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: :I'IYSQL_ATTR_SSL_CA => env( 'MYSQL_ATTR_SS L_CA' ),
    ]) : [],
},
Sign up to request clarification or add additional context in comments.

Comments

0

As a comment suggest, use localhost instead of 127.0.0.1, but also, same error occurs to me and the problem was the Laravel project cache: just use php artisan config:cache to re-cache the files, or just delete all the files inside the bootstrap/cache folder

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.