3

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:

  1. 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.empty var
  2. 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.issue

  1. 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!
JoeyBright
  • 343
  • 1
  • 3
  • 17
  • Do you have the database and the database user on the new environment? – Jite Jun 30 '19 at 20:03
  • I entered to the DB with the user and password successfully then I got the list of databases, finally I could see the name of DB which I am working on! – JoeyBright Jun 30 '19 at 20:12
  • Try to delete the configuration cache manually. To do so, delete: `bootstrap/cache/config.php` (or rename it to keep it as a backup). – mdexp Jun 30 '19 at 23:14
  • Could you also provide the exact steps that you made from start until the error? Did you installed the exact same version of the packages or you did a fresh install of Laravel and more the old code? Which version of Laravel are you on? – mdexp Jun 30 '19 at 23:15

4 Answers4

0

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
Udo E.
  • 2,665
  • 2
  • 21
  • 33
  • I mentioned in the 2nd part of my further information which I tested DB connection and they're working properly! – JoeyBright Jul 01 '19 at 12:49
  • From your post, it means you have not setup the user "Javad" to have `read` access to the database "nlp". if you have phpmyadmin or mysql workbench, you can cross check this. – Udo E. Jul 01 '19 at 13:20
  • the problem isn't your `.env` file. You must go to your database directly either through console or any other user interface and make sure that there is a user named "Javad" that has `read` and `write` access to an existing database schema named "nlp" – Udo E. Jul 01 '19 at 13:31
  • what type of database do you use? – Udo E. Jul 01 '19 at 13:32
  • Dude, I checked permissions, I granted the user to my DB and it has complete permissions to CRUD over the tables. – JoeyBright Jul 01 '19 at 13:36
  • Then try running your query outside your laravel application. Use the database console or a query script in Phpmyadmin, to see if you get same error – Udo E. Jul 01 '19 at 13:42
  • I tried it in console, interestingly it says, unknown column 'nlp' in where clause. I tested this query: select * from information_schema.tables where table_schema=nlp and table_name=page; – JoeyBright Jul 01 '19 at 14:02
  • I put nlp and pages in double quotations sth like "" then it worked – JoeyBright Jul 01 '19 at 14:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195812/discussion-between-joyebright-and-udo-e). – JoeyBright Jul 01 '19 at 14:13
0

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.

sdebarun
  • 99
  • 8
0

Step 1: Go to the project path project_name\bootstrap\cache folder and remove the marked file config.php from the mentioned folder. enter image description here

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!

Majbah Habib
  • 8,058
  • 3
  • 36
  • 38
-1

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)

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64