0

I know this question has been and answered before, but none of the answers apply in my situation. Essentially, I have a Laravel install. I try to run

php artisan migrate

I get the following error:

 Access denied for user 'homestead'@'localhost'

Now here's the deal. I am not using homestead. It's a standard LAMP install and I have changed the database settings in config/database.php and in the .env file to reflect the correct username and password for my database. I can find no logical reason for artisan to still be attempting to use the homestead user. My APP_ENV is set to local and there is no production folder in either the app or config folders. I'm at a loss as to where it is pulling the homestead user.

ETA:

I have restarted apache, and run both

php artisan config:clear 

and

php artisan cache:clear

It's still pulling the homestead user from something, but I simply cannot figure out where.

Blind Fish
  • 998
  • 4
  • 14
  • 25
  • Have you tried `php artisan cache:clear`? – camelCase Jan 07 '16 at 20:20
  • Responding with an edit to the OP – Blind Fish Jan 07 '16 at 20:24
  • I also use `XAMPP` with my local Laravel installs, haven't experienced this issue before though. If you hard code the settings in `config/database.php` does the issue clear? – camelCase Jan 07 '16 at 20:42
  • No. I have the DB setting in both .env and config/database.php set to the proper credentials. There is simply no reason for it to be using the user "Homestead" as that user does not exist in any manner in either .env or config/database.php. I just can't figure out where it's drawing that Homestead user from – Blind Fish Jan 07 '16 at 20:44
  • Agreed, very odd. What does `php artisan tinker` then `App::environment();` output? Not sure how it would be in an environment other than `local` since you've already set it in the `.env` but just trying to think outside the box. – camelCase Jan 07 '16 at 20:53
  • It does not seem possible for me. Are you really sure, you are 100% sure you are running php artisan migrate from correct directory? Are you 100% sure you don't use homestead? Are you 100% sure you have `.env` file (with dot at the beginning and no spaces before or after name?) – Marcin Nabiałek Jan 07 '16 at 20:54
  • Sure on all counts. As it's a new build I think I'm just going to trash it and laravel, restart the entire machine, and reinstall to see if it happens again. – Blind Fish Jan 07 '16 at 20:59

3 Answers3

0

This is a good task to practice debugging skills! :)

So, it's obvious that Laravel gets 'homestead' username from somewhere – which could be a config file, a default value in the code (in reality this is unlikely but we are debugging), etc.

So my first step would be to execute this while in the base folder of your Laravel app:

find . -type f -size -30k -exec grep -H "homestead" \{\} \;

Which would look for files smaller than 30 kilobytes containing 'homestead' anywhere inside, and in case if found – show filename and the line containing this pattern. We can safely assume that 'homestead' is not stored anywhere in the database because it's used to access the database, so it's necessary beforehand.

Once you find the place, fixing the bug may be as easy as editing the file!

If find returns no results, there are still possibilities:

  1. If your Linux user is 'homestead' and you try to connect to MySQL with no username specified, 'homestead' will be used automatically. Which would mean that Laravel for some reason cannot access your configuration files (permissions? wrong path?)

  2. Check storage/logs/laravel.log and see the last error in more details. Go through the code file by file (list of files is given in the error, start from the top) and see how it fetches MySQL username.

Denis Mysenko
  • 6,366
  • 1
  • 24
  • 33
0

I truly have no idea what happened with that particular build, but I am closing this question just to be done with it. I trashed the build and started over without any problem whatsoever. What happened there will forever remain a mystery.

Blind Fish
  • 998
  • 4
  • 14
  • 25
-1

You can have multiple database.php config files. The config file that is loaded is dependent upon the context in which the application is executed.

For example, I have three different database.php config files in my project:

app/config/database.php
app/config/local/database.php
app/config/testing/database.php

In my "testing" config file, I have two different connections defined:

return [
    'default'     => 'sqlite',

    'connections' => array(
        'mysql'  => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'test',
            'username'  => 'user',
            'password'  => 'secret',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),
        'sqlite' => array(
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => ''
        ),
    )
];

Notice that the default key references sqlite, so it does not matter what credentials I enter into the mysql definition. (Unless I override the default value at runtime using Config::set('database.default', 'mysql'))

Search your config/ directory for the string 'homestead'. You'll find the config file that your application is loading. Change the default parameter to match the connection that you want to use.

Ben Harold
  • 6,242
  • 6
  • 47
  • 71