3

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 ?

Pooriya Mostaan
  • 257
  • 1
  • 5
  • 21
  • nothing in that error lines up with your env file. Make sure its called .env . The error says the supplied user is root with no password .. – wschopohl Jul 27 '20 at 13:44
  • It says "using password: NO" maybe put your password in quotes to avoid errors? – jewishmoses Jul 27 '20 at 13:46

4 Answers4

2

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.

pr1nc3
  • 8,108
  • 3
  • 23
  • 36
  • 1
    This is only true if you have config cache enabled. You can just as easily disable config cache for local development. – Kurt Friars Jul 27 '20 at 13:45
  • Well 99% of this kind of problems i've see they were coming because the app was not reading the env file. Also laravel needs to set's the cache so it can use the env – pr1nc3 Jul 27 '20 at 13:46
  • https://stackoverflow.com/questions/62820384/laravel-environment-variableswithout-default-value-passed-in-method-not-workin/62820726#62820726 – Kurt Friars Jul 27 '20 at 13:47
  • I don't see why to remove cache and how is that relevant to the question – pr1nc3 Jul 27 '20 at 13:48
  • Your answer ```php artisan optimize``` is just an alias for ```php artisan config:clear``` ```php artisan config:cache``` ```php artisan route:clear``` ```php artisan route:cache``` the point of my comment is that telling people blindly to start using this command is not always correct. Ie) caching on local development environment. – Kurt Friars Jul 27 '20 at 13:51
  • What you are saying is that he may want to keep his routes cleared and config his cache. Well that's unlikely in my opinion but config:cache is tackling specific that issue so i will change my answer. – pr1nc3 Jul 27 '20 at 13:58
  • how can i run php artisan config:cache? should i run in my phpstorm and upload again ? – Pooriya Mostaan Jul 27 '20 at 14:02
  • open a terminal, go to your project and run the command. You can open a normal terminal or one in php storm. as long as you are in the project folder you will be able to run artisan commands – pr1nc3 Jul 27 '20 at 14:02
  • i know, but my project is now on server c-panel, can i run this commond on cpanel or i have to run this commond in my local, and upload project again ? – Pooriya Mostaan Jul 27 '20 at 14:04
  • You have to run it in the environment you need. So if you are in production then you have to ssh to your server or access it in general and run it there. – pr1nc3 Jul 27 '20 at 14:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218694/discussion-between-waltun-and-pr1nc3). – Pooriya Mostaan Jul 27 '20 at 14:43
2

Multiple reasons can be the cause.

  1. This can happen when the server has already been started before updating database details on your .ENV file.
  2. It could also be from inputting wrong database authentication details.

Solution

  1. Restart the server anytime you update values on your .ENV file.
  2. Ensure you use the correct authentication details or better still create a new database user.
Dharman
  • 30,962
  • 25
  • 85
  • 135
Uhweeka
  • 51
  • 1
  • 4
1

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 ^^
abdessamad
  • 11
  • 1
  • 4
  • 1
    It'd be nice if you could provide more information on how this solves the question or how the output of that route helps solving it. – shaedrich Mar 29 '21 at 10:36
  • yesterday i did have the same probleme and i put that route on my web.php i called it on my browser after a while i checked home page so it was working. – abdessamad Mar 30 '21 at 08:42
  • This command clears the cache and re-caches the configuration. This behavior indicates that the configuration was cached before and therefore changes to the configuration didn't come to effect until you cleared your cache. – shaedrich Mar 30 '21 at 09:04
  • All what i know that it has worked for me so its prety cool thats why i shared it her ^^ – abdessamad Mar 31 '21 at 10:07
1

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.

NAND
  • 663
  • 8
  • 22
Samira kalantari
  • 320
  • 1
  • 2
  • 16