I'm using Laravel 5 and when I am running php artisan route:list, it always gives me an error of SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES). This shouldn't be because my application will not be connecting to any database since it will be a static website.
I tried removing the variables on the .env file:
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Just still gives me errors. It seems like it is still connecting to the database wherein it shouldn't make any database connection.
I was experiencing the same issues when I upgraded my Laravel installer from v1.1 to v1.2.
It appears that the routes.php file by default is adding the Authentication route:
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
This causes to display an error message to what you were describing:
$ php artisan route:list
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)
I resolved this by removing the scaffolding included within Laravel by executing the following command:
$ php artisan fresh
Or by simply deleting the Auth route within the file itself.
You should now be able to run: php artisan route:list
Hope this helps!
This might be the problem of localhost. Do check your WAMP, MAMP, LAMP and XAMP MySql server if you are using any of them.
This have solve my problem:
It looks like artisan might be working in the wrong environment. Run "php artisan tinker", then "App::environment();" to see which environment Artisan is running in. If it is something other than production, you need to create a folder with that environments name within your app/config folder, and put a copy of the "database.php" file in it.
After That if you are not doing any DB related task it will not access DB.
I found answer here
Alternatively You can run following command to resolve this issue:
php artisan migrate:install --env="local"
After this run you command:
php artisan route:list
Enjoy.
Related
I am building a basic CRUD app using Laravel 7 Homestead in a Vagrant VM. The root address http://crud-app.local.test works, but when I add a defined route (http://crud-app.local.test/cats) I get this error page:
Error message in browser when navigating to '/cats' route.
So far I have:
Verified my MySQL password matches in the .env file and in practice
Changed the MYSQL password so that it's no longer empty (and made sure it matches what's in the .env file)
Ran php artisan config:cache
Ran php artisan config:clear followed by php artisan cache:clear
Changed 127.0.0.1 to localhost
Made sure the database defined in the .env file exists (crud)
Ran php artisan migrate (no errors, and the cats table exists in the crud database)
Restarted and re-provisioned the machine (vagrant reload --provision)
I'm at a loss now.
Make sure that you give "root" permissions to read from the database that you've created. As it's root#localhost rather than root#127.0.0.1 sometimes mysql differentiates. Just check the permissions that root#localhost has for the database and if you update them, flush the privileges.
I transferred a Laravel project based on moving Laravel project between computers
Everything was fine at the first look. I could install the composer without any problems, then I set my environmental variables in my .env such as database name, database user and so on.
When I started using the following command,
php artisan cache: clear
I got these two errors,
In Connection.php line 664:
SQLSTATE[HY000] [1045] Acess denied for user 'root'#'localhost' (using password: Yes) (SQL: select * from information_schema.tables where tabale_schema = *** and table_name = ****)
In Connector.php line 67:
SQLSTATE [HY000] [1045] Access denied for user 'root'#'localhost' (using password: Yes)
Further Information:
It seems .env has not been read by the application because when I browse the homepage of the app, I got Whoops error which shows environmental variable is empty.
I tested my database connection such as its username, password, and other parameters, I know they are working properly.
In the end, I attached a photo in order to elaborate on the issue.
Interestingly, in my .env file, DB_DATABASE value is "nlp" and DB_USERNAME equals "Javad" but as you can see in the errors, they are not working, and the Artisan assumes the root as the user!
After you move a Laravel project to another location, The first thing you have to do is regenerate APP_KEY in the .env file by running the command from your application root directory:
php artisan key:generate
After that, you reconfigure your cache:
php artisan config:cache
Additionally, make sure all your database parameters in your .env file and config/database.php are correct and the same as your previous Laravel setup - You can change them manually and then reconfigure your cache as shown above. If not (for instance, the database name is changed), you may have to rerun your database migrations and seeders again:
php artisan migrate
and
php artisan db:seed
I think the configuration files are not writable by the apache user, considering you are using apache. Make sure you have given write permission to bootstrap/cache for the user. This directory contains the cached configuration files.If that is the case the congratulations will be loaded from here and your previously used configuration will be loaded which may be causing the issue.
Also you need to give write permission to the storage directory too. As there is the log file and apache user needs to write on that too.
Step 1: Go to the project path project_name\bootstrap\cache folder and remove the marked file config.php from the mentioned folder.
Step 2: Run the following command
composer dump-autoload
php artisan clear-compiled
php artisan config:clear
php artisan cache:clear
php artisan config:cache
I hope that it will work now!
Open the .env file and edit it. Just set up correct DB credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username, If no username has been set then by default there is a root as a username
DB_PASSWORD= // Your Database Password, If no password is set on the database, clear it
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache
If there is still the same error then try another possible solution.
I had also face the same problem, I tried all the possible answers in StackOverflow but nothing could help me, this solution worked on the first try:
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.
I found this solution from here laravel.io (Read the solution of Byjml)
I accidentally deleted the database for my project so I am trying to recreate all those tables using php artisan migrate.
I can log into MySQL with mysql -u root -p and then I enter in the password of "password" which will allow me to see all my databases. Since I deleted my database I created another database "endorsify_dev" using Create Database endorsify_dev sql command.
Then, I went to do php artisan migrate, but that gave me an error that I cannot figure out.
My .env file:
The Users in Mysql:
Databases:
Error:
You connected yourself with mysql cli clent as root and with a password. But you PHP error indicated (using password: NO).
I assume your php code (Connection.php and PDOConnection.php) is trying to connect to the mysql database without using DB_PASSWORD provided in your .env file.
This error basically comes from changing .env file values.
SQLSTATE[HY000] [1045] ACCESS denied for user 'root'#'localhost'
(using password: NO)
Your .env file configuration should be something like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=endorsify_dev // Your Database Name
DB_USERNAME=root // Your Database Username
DB_PASSWORD= // Your Database Password
NOTE: If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed
If All is correct then After completion of .env edit, You can clear the configuration cache with the following artisan command: php artisan config:cache
Also, check in config/database.php, Check that the old database name has not been used on it.
Also, If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values
To run all of your outstanding migrations, execute the migrate Artisan command:php artisan migrate
Try in your env:
DB_PASSWORD= 'YourPassword'
I've been trying to get data from my database in laravel 5.7.3, but it seems to be using the wrong database name, username and password as it returns this error:
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `tasks`)
My .env file database section is also according to my needs and set like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mrdb
DB_USERNAME=root
DB_PASSWORD=
PS: My app environment is still local. I can also migrate and put in data into database with artisan tinker without issues, but cannot just fetch data from the database.
The only way it gets to work is to change config/database.php mysql section to my parameters, which I believe it isn't just right.
Why is the .env not wanting the change when the database is called?
Laravel uses caching to speed up your sites loading times, one of the things laravel caches is the config files located in the config/ directory. Most of these files do have references to the .env file by using the env() helper function.
One can create a config cache by using php artisan config:cache which will then be stored in bootstrap/cache/config.php.
To remove this specific cache you can use php artisan config:clear, to clear all cache use php artisan cache:clear.
This is cache issue use these commands
php artisan cache:clear
php artisan config:cache
After that delete all cache file ie inside
storage/framework/views
i cannot connect to database after clearing even php artisan is not working.
here is how i clear config caches:
php artisan cache:clear
then it's cleared successfully but when i run:
php artisan config:cache
i got this error:
<pre><strong>ERROR:</strong> Can't connect to the database server. SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO)</pre>%
i also tried: composer dump-autoload
but still no luck. Once in the past i got same error and i was able to solve it but no idea how. If someone knows solution then kindly explain it as well.
My php version: PHP 7.2.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 5 2018 05:00:15) ( NTS )
Thank you!
User you are using to connect the database in not having privilege to connect, please provide that access to your db user
I don't know if i'm allowed to answer my own question or not. Let me know if it's not allowed to answer to your question.
In bootstrap directory which is located in root of your app. There i saw cache directory and then i just delete it and run:
composer dump-autoload
then it's works. But even if i try to run:
php artisan config:cache
it gonna be successful. But if after this you may get same error again:
php artisan serve
ERROR: Can't connect to the database server. SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO)
After this i try to delete config.php inside bootstrap/cache/.
it gonna work even after deleting that file.