config sticked in laravel app on shared hosting - php

I've deploy a laravel API some months ago into a shared hosting (banahosting). It's been working fine until yesterday that all API endpoints returns an error:
Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user '####'#'localhost' (using password: YES) (SQL: select `destinations`.*, (select count(*) from `experiences` where `destinations`.`id` = `experiences`.`destination_id`) as `experiences_count` from `destinations` order by `id` desc) in file /###/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 669
Its weird because no-one else than me has access to the hosting, so i supposed that maybe some strange security function of this shared hosting has changed the password of the db user so i just changed it again, updated the .env file and ran the commands to clear artisan cache but the error has remained.
I've tried creating a new DB user and then i found the real problem: even when i changed the db user on the .env file, the error says that the user which is trying to access is the same. I mean, the error should say something like "Access denied for user 'NEW_USER'#'localhost'" but instead it says "Access denied for user 'OLD_USER'#'localhost'"
I also tried setting directly the user and password into the file /config/database.php or deleting completely the .env file but the error is exactly the same.
The support team of the hosting tried to help me too, they told me that they cleaned the cache of the server but it didn't work and they don't know what could be happening.
The command after every changed i've tried is php artisan config:clear and php artisan config:cache, i've also tried with php artisan config:clear and php artisan optimize

Related

SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select * from `permissions`)

I upload my project on C-panel and set my connection for database in my env file, it was ok for me with the same settings, but now i don't know why it's happening, this is error :
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select *
from `permissions`)
And this is my env file settings for database :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thermota_db
DB_USERNAME=thermota_user
DB_PASSWORD= { my password }
i don't know this permissions in error, is my permissions_table ?
and why error for this table ?
Multiple reasons can be the cause.
This can happen when the server has already been started before updating database details on your .ENV file.
It could also be from inputting wrong database authentication details.
Solution
Restart the server anytime you update values on your .ENV file.
Ensure you use the correct authentication details or better still create a new database user.
Run this command:
php artisan config:cache
You are trying to use a different user that means that your root value is not used.
You need to cache your env field to use the values in it. That goes for every change you make as well.
if ur on online server do the following steps :
1 - locate to : /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
2 - add thoes line of code on the begining of this function : createConnection($dsn, array $config, array $options)
3 - code to add : \Artisan::call('config:cache');
4 - refresh ur home page
5 - remove the "\Artisan::call('config:cache');" line code
6 - enjoye ^^
I had the same issue and I couldn't run config:cache artisan command even with
Artisan::call('config:cache');.
So I done this and solved my issue:
artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recach them. That's why it still works after deleting .env.
https://laravel.com/docs/5.6/configuration#configuration-caching
If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.

MySQL+Laravel: SQLSTATE[HY000] [1045] Access denied for user 'so'#'localhost' but connection data is OK and config cache is cleared

I need help here, because it's driving me crazy. I'm trying to connect to the remote production DB but I'm unable. I have read tons of posts about this that are focusing on the credentials and also running the following commands to clean config that are stored in Laravel cache:
php artisan cache:clear
php artisan config:cache
php artisan config:clear
Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Any of these are working for me.
I have checked very well the credentials both in my .env file and my database.php. I'm able to connect to a local database by using the ip "127.0.0.1" but I'm unable with the production DB stored in Google Cloud. It's good to mention that my local IP is allowed to access that Database and I'm able to connect by using MySql Workbench.
Here is what I see when I perform "php artisan tinker" and then "DB::connection()->getPdo();" to check my connection from terminal:
The only thing that calls my attention is the message containing "so#localhost" when I'm not performing a connection to localhost but I don't know if that's related with the issue.
Any other suggestion? I have lost too much time trying to find out what could be happening.
EDIT 1: Laravel Framework 5.8.38
After two days fighting with this one, I readed tons of posts and a lot of unuseful solutions I have found my solution by looking at this video.
Basically, you must stop you XAMPP MySQL Server and open C:\xampp\mysql\bin\my.ini and edit by adding the following command "skip-grant-tables" after the [mysqld] attribute. The result in this file might look this way:
# The MySQL server
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
socket="C:/xampp/mysql/mysql.sock"
...
After that, I ran "php artisan tinker" and DB::connection()->getPdo(); and everything was connected again, but it's good if you first clean your cache and config.

Can't connect to MySQL database from Laravel, even though I created the required user

I'm getting this error when I open a view that requires data:
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `books`)
I created the homestead#localhost user in MySQL with the specified password, but I'm still getting the error... What might cause this and how can i fix it? Thanks! :) (I already tried restarting the php artisan serve process and running php artisan config:clear...)
This is really stupid but Laravel was lying about the password it was using; it was actually "secret" as defined in the .env file!

Fresh-installation laravel project can't access postgresql database but can do php migrate

I already asked a question about this 2 days ago, here are the links
Got "password authentication failed for user" but in pgAdmin 3 its working
But I still didn't get an answer to solve the problem.
So I tried to create a new laravel project, then edit the .env file, check if php artisan migrate can run.
After I run php artisan migrate it's running, so it means that my credentials to PostgreSQL database are correct right? if not it will tell you password authentication failed for user "postgres", but I don't get any error at all, so I go to the next step. Now after I make sure everything is OK i run php artisan make:auth, it's a success without error at all, so I go to the web browser then run the site, I clicked the register / login button, fill the fields, submit then, it's happened again the nightmare
I got this message from the website
SQLSTATE[08006] [7] FATAL: password authentication failed for user "postgres" FATAL: password authentication failed for user "postgres" (SQL: select count(*) as aggregate from "users" where "email" = test#test.com)
Even though php artisan migrate run really well, so I've no idea why it's happening. Is there somebody that ever run into this problem before? or maybe why it's happening?
I already search all keywords that possible to fix this problem, but I can't found the answer, it's really stressed me out.
for the info I'm using:
PostgreSQL 9.6.8
Laravel 5.6
Ubuntu 17.10
Edited: Here is my pg_hba.conf
Check your database.php file in config directory, and check the pgsql array. If accessing DB credential values from .env not worked there, test it by directly putting credentials there. hope it will help. Artisan commands work by accessing the credentials from .env files directly,not from database.php that's why migration worked.
I had a similar problem, my generated password contained the character: '#'. This made it a comment line, ignoring the rest of the password. I just changed my password.

Laravel 5.4 - I can't even execute php artisan config:clear - [Illuminate\Database\QueryException] SQLSTATE[HY000] [1044]

My project was working fine. After copy and pasting files in another Mac localhost, I always get the same error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database '***' (SQL: select * from roles)
[PDOException]
SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database '***'
I already checked the .env file, but it seems Laravel can't execute code at this point. This 'roles' is a table with many to many relations trough pivot table.
Note 1: Fresh Laravel aplications works fine.
Note 2: Because I can't clear the cache, Laravel always considers the user to b be blank.
Can someone help me, please?
Thank you!
If your connection string is cached it will continue to use that.
You can try clearing and rebuilding the connection and config strings with
php artisan config:cache
or you can clear explicitly with:
php artisan cache:clear
It that that does not work I think your database is not connecting for other reasons.
Are you using MySQL or SQL Server?
I replaced files off a fresh application with my files(models, controllers, middlewares, migrations ...) and everything worked fine.
The solution:
https://laracasts.com/discuss/channels/general-discussion/base-table-or-view-not-found-1146-table-doesnt-exist/replies/151761

Categories