Access denied for user ‘homestead’@’localhost’ laravel 5

Rakesh Sharma      27 Comments  

How to solve error – Access denied for user ‘homestead’@’localhost’ laravel 5

After install laravel 5 successfully and setup database configuration correctly. when i go to auth/register page and filling up user details and click on submit button to process and i found an error (Access denied for user ‘homestead’@’localhost’ laravel 5) like below

PDOException in Connector.php line 47: SQLSTATE[28000] [1045] Access denied for user ‘homestead’@’localhost’ (using password: YES)

so i think there is problem with database connection or may be issue with user permission. so i tried more time to solve and serched over internet for solution. after more search i found a solution and really a good solution so i am sharing this solution for solve this type of error may be some of string different in this error like [28000] or [HY000] etc.

PDOException in Connector.php line 47: SQLSTATE[28000] [1045] Access denied for user ‘homestead’@’localhost’ (using password: YES)

Access denied for user homestead@localhost laravel 5

I have also stuck with this error in my ubuntu terminal when i run “artisan” command i found below error in terminal.


[PDOException] SQLSTATE[28000] [1045] Access denied for user ‘homestead’@’localhost’ (using password: YES) looks like same error different is not showing any file line number.

The reason of Access denied for user ‘homestead’@’localhost’ laravel 5 error is caching-issue of the .env.php file cause Laravel 5 is using environment based configuration in your .env file.

Why Environment Configuration :-

It’s often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver locally than you do on your production server. It’s easy using environment based configuration.

Laravel utilizes the DotEnv PHP library by Vance Lucas. In fresh Laravel installation, you will see a .env.example file in the root directory of your application. If you are installing Laravel via Composer, this file will automatically be renamed to .env. else, you need to rename the file manually. For more about Environment Configuration

default .env file looks like :-





How to solve this error :- let’s see how we can solve this PDOException in Connector.php line 47: SQLSTATE[28000] [1045] Access denied for user ‘homestead’@’localhost’ (using password: YES) error in laravel 5.

1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files) in your editor and change database configuration setting. then save your .env file


2. then restart your apache server/web server. and refresh your page and you have done
3. If still issue try to run below command to clear the old configuration cache file.

php artisan config:clear

Now run your user register page and enjoy new laravel 5. Now you are done with Access denied for user ‘homestead’@’localhost’ laravel 5

  • Kristian

    thanks! Nice article…been trying to solve this for a long time now. Also if your server is running (php artisan serve) you must restart the server in order to see the changes

    • Raman sai

      thanks alot..saved my time

  • Ireco Gnizedyou

    when local environment is homestead and you connect to different database then you will have problems to use tinker

  • Codi

    Wow, thank you very much, that was really helpful. As Jobs said: “It just works”

  • Juan Antonio Chuc Méndez

    Thank you very much!!!!

  • Tunde Ojediran

    What a relief. Thanks a lot!!!

  • Milder Lisondra

    Finally. Thank you for sharing this. I’ve been wondering what in the world was going on. Just seems so counter intuitive to config and the environment.

  • after all I’ve done it=) thanks a lot!!

  • Zaid Rsh

    Thank you, It saved me much time :)

  • Fazle Kabeer Khan

    thanks a lot

  • Here is the solution for those who are using Xamp

    • Yasser Hossam

      thx that helped me a lot :)

  • rahulanand77

    Perfect solution. I changed the DB settings in database.php file in config, but forgot to change DB details on .env file. Thanks man , you are a life saver.


    Rahul Anand.

  • Ambition Pete

    I found out that if we can write to the database, then the connection is working fine. We all faced the issue when trying to retrieve from database. I resolved this issue by restarting the server. That worked for me in Ubuntu 14.04

  • Kyle Reierson

    Nice! This worked for me. Thanks!

  • Ikram Hasib

    thanks. everythins is ok. only i don’t know to restart the server.. thanks again..

  • btistaa

    thanks for php artisan config:clear

  • Narciso Pereira de Sousa

    Thanks :)

  • Codename CobWeb

    Thanks !!! :)

  • Fongoh Tayong

    You are the bomb. Thanks man.

  • Victor

    SQLSTATE[HY000] [1698] Access denied for user ‘root’@’localhost’


    my .env


    my database

    ‘driver’ => ‘mysql’,
    ‘host’ => env(‘DB_HOST’, ‘localhost’),
    ‘port’ => env(‘DB_PORT’, ‘3306’),
    ‘database’ => env(‘DB_DATABASE’, ‘appmarket’),
    ‘username’ => env(‘DB_USERNAME’, ‘root’),
    ‘password’ => env(‘DB_PASSWORD’, ‘macua32A’),

    fix not config:clear

    • Manuel Ramirez

      wrong config in your database.php, should be like this
      ‘driver’ => ‘mysql’,
      ‘host’ => env(‘DB_HOST’),
      ‘port’ => env(‘DB_PORT’),
      ‘database’ => env(‘DB_DATABASE’),
      ‘username’ => env(‘DB_USERNAME’),
      ‘password’ => env(‘DB_PASSWORD’),

  • thank you so much

  • Jose Luis Bru Quiles

    Thx a lot!!!

  • pradeep keshari

    Thanku very much it works

  • Abhi Bhardwaj (Rohan)

    its still showing the same error . I’m not getting that when My project’s configuration is 100% right then why its showing the error.

  • Vipin Saini

    Problem resolved.