Laravel app not connecting after deployment to live server - laravel

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

Related

Why am i getting this error when i try to submit a form (Illuminate\Database\QueryException SQLSTATE[28000] [1045] Access denied for user)

enter image description here
why am i getting this error when i try to submit the contact form ?
And i get this issue only after hosting the website.
Website works fine in the local machine with contact form.
i changed the .env file according to the hosted db credentials.
Illuminate\Database\QueryException
SQLSTATE[28000] [1045] Access denied for user 'cargills'#'localhost' (using password: YES) (SQL: insert into
contacts (name, address, phone, email, subject,
division, message, updated_at, created_at) values (sadsa,
dfsdf, asdsad, dsfsd#asdfsa, Customer Enquiry, Exports, sadsad,
2020-02-21 11:27:32, 2020-02-21 11:27:32))
For some reason in your production you still try to connect to localhost (127.0.0.1).
Put the right ip in your env file to your host, check the port and then in the production console run:
php artisan config:cache so laravel get's the right credentials from your .env file.
There might be several reasons.
Your user and password is incorrect
User has not enough privileges to select or update that table
Incorrect hostname, sometimes changing DB_HOST to 127.0.0.1 solves that
Also make sure you don't have cached wrong/testing user and password
run
php artisan:cache clear
Then run:
php artisan config:cache
To cache new .env file
Hope this helps you

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)

.env file not updating in server?

After I uploaded my Laravel project in Cpanel I have to configure my env file according to my database.
I put database name, database user name and password also.
but after I save in the database and refresh my browser. it says
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select * from sliders)
even though I have changed env file in server. but still showing me root#localhost.
Can't figure it out how to solve this.
run php artisan config:clear
mostly because of .env being cached

"SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' : Laravel 5.3

Hi I'm having a problem with laravel 5.3
project was moved from one host to another
and I've updated the .env file
The project was working well in the old host
but when I moved to the new host, the site displaying this error
1/2
PDOException in Connector.php line 119: SQLSTATE[HY000] [1045] Access denied for user 'xxxx'#'localhost' (using password: YES)
2/2
QueryException in Connection.php line 770: SQLSTATE[HY000] [1045] Access denied for user 'xxxx'#'localhost' (using password: YES) (SQL: select * from countries)
xxxx => The user name for the old database was not updated. i do not know the reasonenter image description here
There are many possible reasons to throw this exception, let's explore them:
There is a kind of cache in the .env file. In this case, you could only rewrite the DB variables, run php artisan config:clear and restart the server.
Maybe some of the DB variables aren't right. In this case, you could check out the values.
The user is right but he hasn't permission to access the database. In this case, you could check out the user permissions.
I hope that one of these tips help you.
Check the .env file it should include all value like CONNECTION, HOST, PORT, etc.
php artisan config:clear
composer dump-autoload and restart the server
the SQLSQLSTATE[HY000] [1045] seems like the password in your .env file doesn't match with the database's password.
You can check the database pass and user in the new server and put into your .env file.
Good luck

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.

Resources