Access denied 'homestead'#'localhost' when running a Laravel Command - laravel

I'm having some trouble getting Laravel to connect to my database, when using a custom Artisan command.
I can post my command but I'll skip to my db settings as I suspect that is what is wrong. In start.php I have:
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
and then I have no local/database.php files in my config. Instead I have a .env.local.php which works great for everything except this. All database settings are set as 'DB_NAME => getenv('DB_NAME'); etc.
When I run php artisan custom:command I get the following:
[Illuminate\Database\QueryException]
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select * from `users` where `paused_until` = 3)
Then if I run
php artisan fdb:reactivate-paused --env=local
I seem to get much closer but still get:
Access denied for user 'homestead'#'localhost' (using password: YES)
Is it that Laravel doesn't know to use the .env.local.php file when I am running commands in the terminal? All my migrate and db:seed queries seem to work fine. Can anyone point me in the right direction?

Looking at it again this morning, I must have been 100% burnt out. I was running the command from my Local Machine, not the Homestead VM.

Related

Laravel app not connecting after deployment to live server

After deploying my Laravel app to inMotion hosting, I am having issues connecting to the database. What is strange is that if I use a PHP script to test the connection, it works. However, when trying to login I get this error:
SQLSTATE[HY000] [1045] Access denied for user #'localhost' (using password: YES) (SQL: select * from `users` where `email` = .com limit
I am using the exact same username and password in the .env file as I did in the PHP test script. I have tried clearing the cache and also changing the password for the database as well as my username.
Turns out it was the password in the .env file. It had special characters, so I had to add quotation marks around it.
Better if you can clear the config cache and see. You can use the following command to clear the config cache in Laravel:
php artisan config:cache

Laravel can't access database

I cvurrently have a laravel application running on heroku, the issue here is, I keep getting the error that I can't connect to the database: SQLSTATE[HY000] [1045] Access denied for user 'user'#'ec2-54-74-209-179.eu-west-1.compute.amazonaws.com' (using password: YES). Now the host is wrong here, the environment files are TOTALLY different (except for the username) then what the error gives....
How can I resolve this issue?
I've tried to use the DB_URL env, but that gives the same result...
Did you set the .env correctly on what's running on their server?
You can see all your projects in laravel at TOOLS->DEPLOYEMNT->CONFIGURATIONS
add all the info and connect to the remote project. I did the same and changed the .env directly there.
and of course you have to clean all the cache cause even if you change the .env it will not work until you'll clear it
php artisan cache:clear;
php artisan config:clear;
php artisan route:clear;
Obviously this need to be executed on the project on heroku or aws (as it appears from the Error)

Laravel is using the default homestead user details to connect, even though these have been deleted

I am using laravel 5.8.6 and can connect to my database using the artisan migration tool, and can read and write to the database using tinker with no issues.
When I launch the default scaffolding it fails to connect, complaining that the login failed for user homestead#localhost.
I have deleted the .env.example file and cleared the various cache files with no success.
A full search for homestead only reveals log entries:
Illuminate \ Database \ QueryException (1045)
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `users` where `email` =
Any ideas gratefully received.
I had the exact same problem and I just couldn't wrap my mind around how that was even possible. Turns out I seem to have changed the .env file after having started the dev server via php artisan serve. It doesn't pick up changes in the .env config at runtime and it caches the configuration.
After running
php artisan config:clear
, shutting down the dev server and restarting it, the issue was resolved and the database connection successful with the correctly set database credentials.

laravel 5 - when trying to retrive data from phpmyadmin: SQLSTATE HY000 1698 Access denied for user 'root'#'localhost'

That's my first post - I hope my problem explanation will be easy to understand. I just started with Laravel5.
I want to retrive data from mysql database that was successfully created using migrations. I'm following laracast series. I created route, controller and view to display the data. Unfortunatelly, when I enter browser to see it, I constantly get this error:
`SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost'`
enter image description here
My .env and database.php files are configured. Also, I can do migrations with no error (and I see result in phpmyadmin to which I can log in). When I type php artisan tinker, I can do various operations on my databases. The problem arises only when I want to display data in my laravel site.
I did vast research of the problem and tried numerus tips like:
1.change local host to 127.0.0.1
2.change my database login and pass for homeostead, secret
3.I did
`GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY 'Your_Password';`
When I type mysql --user=root -p I can log in but command show databases acts like never ending and shows nothing.
and other ...
Now, I'm at loss for ideas what to do next, please help me. I will appreciate that a lot cos I'm really stucked at this point!
my .env file:
`DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=haslo`
I use homeostead and Laravel 5 on Windows 7
Server type: MySQL5.7.15
PHP version: 7.1
Apache/2.4.23, PHP/7.1
have a look at my answer at Unable to connect to local MySQL DB using Laravel
That could be the answer for you as well.
If you use homestead with vagrant, then laravel will be lunched inside vagrant and 127.0.0.1,3306 will mean the mysql inside vagrant, type vagrant ssh and check for the database.
Try this command:
Php artisan config:clear

Laravel [PDOException] SQLSTATE[HY000] [2002] Connection refused

While pushing homestead repo to live server, i encountered the following error.
I can confirm that i can connect to mysql from the command line using the variables set in the .env file.
I know that it has something to do with this particular setup, as i am effectively operating a similar laravel 5.1 project on the same host.
I noticed that on the error page that i was looking at the top message, which was 3/3. Looking to the 1/3 (the first error) error helped me find the solution.
Laravel was still using the homestead credentials.
i found this by searching:
grep -r "homestead" .
returns
./bootstrap/cache/config.php: 'database' => 'homestead',
To clear the cache all that was left was to do was clear the cache.
php artisan config:cache

Resources