Laravel - Access denied for user 'homestead'#'localhost - laravel

I am learning laravel, and working on a blog application. Anyway, I made my model for articles + migration, and migrated it fine. But now that I want to pull articles from database in my controller, I get "Access denied for user 'homestead'#'localhost".
And yes, I've changed my settings in .env file, and restarted the server. Still wont work. I tried everything from that other thread on this same issue, but nothing worked.
Any help would be appreciated.
EDIT:
Here are the mysql settings in .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=faks_blog
DB_USERNAME=root
DB_PASSWORD=''
If migration worked, then settings must be correct. Otherwise, how would laravel make all those tables?
I also use HeidiSql to access my database, and those login credentials worked.

Just remove empty brackets after DB_PASSWORD
write like this
DB_PASSWORD=
Please tell if it helps

When you make changes to the .env file you should always run php artisan config:cache because Laravel caches config to avoid reading the same files twice.

Related

Laravel doesn't keep session when use SQLite database

I converted my MySQL database to SQLite one, but now the login system is not working anymore. I'm using DATABASE=sqlite and SESSION_DRIVER=file. What's wrong?
When I type my email and password and press Login, the system redirects me at Login page again without any error messages.
I tried to change the redirect route after login many times, and only that are unauthenticated routes are working; This is because Auth::user or auth()->user() are Undefined objects. The login is going well, because if I make a typo in password the system tells me that credentials are wrong.
Obviously, I tried to do queries when SQLite database is set and are working well (App\User::first()->name in login.blade.php, for example).
I tried to revert DB_CONNECTION=mysql and all works as expected (as before too): when I login with my email and password the system redirects me to the dashboard.
I'm using Laravel 5.7 in Windows 10 with SQLite 3.26.
EDIT
Part of my .env file
APP_NAME=*****
APP_ENV=local
APP_KEY=******
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=sqlite
DB_DATABASE=database.sqlite
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
...
SNAPPY_PDF_BIN='C://"Program Files"/wkhtmltopdf/bin/wkhtmltopdf'
SNAPPY_IMG_BIN='C://"Program Files"/wkhtmltopdf/bin/wkhtmltoimage'
SES_KEY=****
SES_SECRET=****
I found the solution. Laravel did not have any problem, the problem was the sqlite database (the file). It was not well converted from mysql to sqlite. In the end the only thing that worked is the "famous" bash script "mysql2sqlite.sh" that you can find here. It only works for me with database empty. With data, I get an error when doing the conversion.
I hope I can help someone, greetings!

LARAVEL switches database automatically on Curl request [duplicate]

I have 2 Laravel applications running on the same server. The server is Apache 2.4 and I have vhosts set up to serve each application on a different domain.
The first application is an API and it's .env file is set up like this:
APP_ENV=production
APP_KEY=YYYYYYYYYYYYYYYYYY
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=https://notify.mysite.com
APP_DOMAIN=notify.mysite.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=notify
DB_USERNAME=YYYYYYYYYYYYYYYYYY
DB_PASSWORD=YYYYYYYYYYYYYYYYYY
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
The second application is a UI that among other things, utilizes the API from the first application. Its .env file is set up like this:
APP_ENV=local
APP_KEY=XXXXXXXXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=https://asapps.mysite.com
APP_DOMAIN=asapps.mysite.com
APP_VERSION=1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=asapps
DB_NOTIFY_DATABASE=notify
DB_FLIGHT_DATABASE=flights
DB_USERNAME=XXXXXXXXXXXXXX
DB_PASSWORD=XXXXXXXXXXXXXX
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
I can send messages to my API from my Swagger editor, from Postman, and from other servers and everything works as expected.
My second application by itself also works as expected.
However, if my second application sends a request to the API, the API application throws this error:
exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'asapps.preprocessor_config' doesn't exist'
in C:\notify\vendor\laravel\framework\src\Illuminate\Database\Connection.php:332
WTH?
The database for the API is set to DB_DATABASE=notify and it definitely does properly use that connection when I send messages from other servers. So why the heck is it trying to use the second application's database
connection when I call the API from that app??? Its almost like it's caching the DB connection and trying to keep using that same one.... How do I stop that?
Table 'asapps.preprocessor_config' doesn't exist'
After more digging (read frantic googling), I found the problem and solution here
The bottom line, when site A accepts a request, php loads it's .env variables for the entire length of the http request. During that request, when site A calls site B, since they are on the same server running the same php, php is still using the .env from site A and does not separately load site B's .env file at all.
The author's better explanation:
The .env file with the variables was created so that people would not push their credentials to github repositories and other places where they may share the source.
Now, being environment variables they become system wide for the entire duration of the http request (in this case script execution). The point is that you got a long running script.
To find a definitive solution you could go one of the three ways.
....
'namespace' the ENV variables.

Laravel - Changed password and now I can't login

today I changed password via MySql admin and now I get error.
You can see it at:
http://domainsmeca.com/admin/login
I am a designer and not programmer, one friend suggested that I ask here.
Hope some nice person can help me.
Thank you in advance.
Ivonne
You can change the password in .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=YourDatabase
DB_USERNAME=urUsername
DB_PASSWORD=Password

Issues when trying to migrate

I am having a problem when trying to make migrate.
MY DATABASE DOES NOT RECEIVE NEW MIGRATION, NO NEW FILES NO UPDATES
From my project;
I do:
php artisan migrate
But nothing shows in my database, I already verify my database and my file .env
Both are correct.
I know you said you verified it, but please check again that the correct database information is entered in your .env file. It should be something like the following for a dev environment:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
You need to edit that data if you haven't and make sure it's correct. You also need to make sure that your database actually exists.
Also make sure you're actually entering the correct command. The general way you should making migrations is:
php artisan make:migration create_example_table --create=example
After that, run
php artisan migrate
Lastly, are you getting any errors in the console? If so, you need to edit your post and post them here.
firts thanks for answering
I had already checked .env file and I replaced database name from my sql (I use phpadmin), and also I changed username and password as I entered on sql server, but there is no migration
I had created a new table using artisan command (besides I have a users table that comes when downloading laravel project). After creating this new table I expected to upload this new one to my database located in sql server, but nothing happen
it shows your users yable already exists, mentions my users tables and not my new table that i just created. It is weird bcz it does not EVEN upload any changes made in default table users.....always answer your table users already exits

Access to database is denied, Laravel

When i try to register new user in my app i get:
SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost'.
I basically created new app, made database for app. Changed in env database user info (I use same user for local development for every project , so it has all permissions).
After that i've tried to change alternative choice in database config (even there is not homestead , there was forge) but nothing changed..
For Users, controller, view , etc. I was simply used php artisan make:auth and then migrate..
Migration did work, so i don't get it where I made mistake.
In your env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=-------(put here your database name);
DB_USERNAME=root
DB_PASSWORD=
Also check your databse.php fileand updated it with proper database connection details.

Resources