Laravel not storing session data in Redis - session

I just decided to switch to Redis to store my session and cache data. But Laravel seems to use local file storage itself.
I have installed the predis composer dependency and have changed the config to:
SESSION_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=secret
REDIS_PORT=6379
also in the config/session.php file, I have used 'connection' => 'redis'. Still, it seems to store all my login cookies and session data in the storage/framework/session
What do I need to do??

It seems you might be using config caching. You should run:
php artisan config:cache
to flush your config data.

Related

Laravel session ID changes on each request

Every time I reload the page, I get a new value out of session()->getId().
Some have suggested adding the laravel_session to the unencrypted cookie exception, but this does not fix it and is not a viable option anyway.
The issue persists no matter which session storage method I use. File, redis, etc all have the same problem.
This is happening on a fresh install of Laravel 7.
Contents of .env:
SESSION_DRIVER=redis
SESSION_LIFETIME=1440
SESSION_DOMAIN=example.test
What's causing this?
That means:
Session driver is not starting up properly
Client you're using to connect to laravel app server does not accept cookies
Cookies are set up for wrong domain and/or path.
For case 1 make sure StartSession middleware exists in app/Kernel.php at $middlewareGroups -> web
For case 3 check this answer. In case your app relies on a single domain/path, I recommend you to remove SESSION_DOMAIN.
Finally, manually remove all sessions from your session driver, then run php artisan config:cache and try again.

Refresh Laravel environment variables on shared hosting

I implemented my website on a shared hosting environment. Works perfect!
But now I changed functionality and want to use 'queues'. In my earlier instance the environment variable 'queue_driver' contained the default value 'sync', and now I changed that to 'database' in the environment file.
Question is now: how to activate this new setting?
I already tried to clear cache and config, but it does not change anything?
Can I enforce refreshment?
Use php artisan config:clear to clear the cached config files.
Maybe also follow up with composer dumpautoload

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

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.

Unable to store session in Database in laravel 5.2

I recently upgraded my application from laravel 5.1 to 5.2 version. Also I am trying to store session in Database which is currently stored in file.
I have changed .env file to include SESSION_DRIVER=database. Also I have changed session.config file to include 'driver' => env('SESSION_DRIVER', 'database') and generated required session table.
But when I tried to login to the application I am getting TokenMismatchException in VerifyCsrfToken.php line 67: If I change SESSION_DRIVER=file then application is working as expected.
But this was not the case in Laravel 5.1 version.
What is changed in Laravel 5.2 version and what steps are required to store user session in database?
I had to deal with this issue myself as well. So the initial steps are as you had already mentioned in your question.
On fresh install of laravel and verify that everything works, change the SESSION_DRIVER=file to SESSION_DRIVER=database
Run the following commands IN ORDER in your console within the directory of your app:
php artisan session:table
composer dump-autoload
php artisan migrate
(This step might be different from what you did) In your config\session.php file search for:
'driver' => env('SESSION_DRIVER', 'file'),
and change it to the following
'driver' => env('SESSION_DRIVER', 'app.database'),
Within the same config\session.php file change the encrypt configuration to true
Set your connection and table name settings appropriately
'connection' => 'database_name_here',
'table' => 'sessions', //here you can change but sessions is recommended until you get more comfortable with how it all works
Attempt to login to your application and check your database to see if it all works.
If more help is needed you can also check a few resources that have helped me solve the issue. Keep in mind these resources are of people having similar issues but maybe your problem is similar to theirs. Only way to find out is to investigate. Hope this helps! =) :
https://laracasts.com/discuss/channels/laravel/how-to-store-users-id-in-session-table-laravel-5
https://laravel.com/docs/5.2/session
(Video tutorial on Laravel Sessions, VERY good place to help you get to where you need to be!)
https://www.youtube.com/watch?v=-FMecyZs5Cg
look it's ok to go with it manual but why don't u use the php artisan make:auth
it creates every thing u need for authentication and also helps u keeping the session instead of doing it manual ?

How to stop Laravel 5 from caching configurations?

It is written in Laravel 5 documentation that php artisan config:cache stores all the app configuration into one single file which makes the application load faster.
I want to know two things:
The first thing is, how to force Laravel to stop caching my app configurations? For example, I want Laravel to read the name of my database and the password from the .env file or from the database.php configuration file, not from the cached data.
The second thing is, where does Laravel store this cached configuration file, so that I can delete it when needed? I know there is an Artisan command for that, which is php artisan config:clear, but I want to know where the file stored.
You can't stop the caching of config files since it doesn't happen automatically. The only thing you need to do, is not call config:cache.
The file itself can be found in bootstrap/cache/config.php.
Note that the location of the compiled config file has changed recently. Yours might also be in vendor/config.php or storage/framework/config.php. With a fresh install or if you run composer update the file should be in bootstrap/cache though.
As per the post here: https://github.com/laravel/framework/issues/2501
"Change cache driver to array for the local environment."
For me this involves adding CACHE_DRIVER=array to my .env file. This is then picked up by my config/cache.php file which includes the line:
'default' => env('CACHE_DRIVER', 'file'),
Obviously you could change it directly in the config/cache.php but I'd prefer to use the .env file so I can disable it for development sites and enable for production.

Resources