Laravel Lumen Memcached not found

PhpLaravelMemcachedLumen

Php Problem Overview


Ok, I just started with Lumen and I'm trying to use the Auth, but a call to either Auth::check or any other function of Auth.. leads to the below Error Fatal error: Class 'Memcached' not found in vendor\illuminate\cache\MemcachedConnector.php on line 52. I don't want to use Memcached never used it before.

I disabled it in the .env file and set the CACHE_DRIVER and SESSION_DRIVER to array, but still shows the same error.

I decided not to use Auth again and to manually handle my authetication with sessions/tokens, but enabling the MiddleWare StartSession results to the same error.

$app->middleware([
 // 'Illuminate\Cookie\Middleware\EncryptCookies',
 // 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
  'Illuminate\Session\Middleware\StartSession',
 // 'Illuminate\View\Middleware\ShareErrorsFromSession',
 // 'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
]);

Please I'd be so glad if anyone can really help me out here

EDIT

After going A little Deep in the framework I Hard Coded the session driver name in the SessionManager Class within the method getSessionConfig

public function getSessionConfig()
{
	$this->setDefaultDriver("cookie");//I added this line
	return $this->app['config']['session'];
}

It works though but not a good way of doing things. There is no config file, i believe all configurations are written in .env file, but i really don't know why the session_driver and cache_driver is defaulted to memecached even after changing it in the .env and then ran composer dump-autoload ... Lumen :(

EDIT This is my .env file

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomKey!!!

APP_LOCALE=en
APP_FALLBACK_LOCALE=en

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=array
SESSION_DRIVER=cookie
QUEUE_DRIVER=database

I already have this line uncommented in my bootsrap/app.php

 Dotenv::load(__DIR__.'/../');

My DataBase configuration works perfectly so the .env file is loaded quite alright.

Php Solutions


Solution 1 - Php

I spent 3 hours on this problem today. With the help of the post of demve in this topic, I found the solution. Very simple! I hope it won't affect me later in my development.

Just to it, in the .env file :

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=array

Ok, I make an UPDATE because I was faced with a new problem about the session. In fact, when you set the previous parameters, your session won't be persistent, like said in the documentation: array - sessions will be stored in a simple PHP array and will not be persisted across requests.

So I have to change it, always in .env a file like that :

SESSION_DRIVER=cookie

With a var_dump(Session::all()); I now can see the whole values of my session

Solution 2 - Php

You may need to restart your server, especially if you're using php artisan serve.

Lumen doesn't appear to pick up .env changes per-request.

I had exactly the same issue - trying to use file cache, but received errors regarding Memcached - restarting the server reloads the .env file.

Solution 3 - Php

This issue resolved when i installed this package so try at least

First i tried this and it works fine

CACHE_DRIVER = array 

but then thought about what is memcached

Then i tried this and it works fine without changing driver memcached

apt-get install php-memcached 

yum package manager or in Amazon Linux.

yum install php-memcached -y

Solution 4 - Php

In .env file replace

#This line:- 
  CACHE_DRIVER = memcached

#With this:- 
   CACHE_DRIVER = array

Solution 5 - Php

Make sure not to get caught out by your .env file not being loaded, which by default it's commented out in Lumen. So if you are specifying a different cache driver in your .env, do the following.

> Note: If you are using the .env file to configure your application, don't forget to uncomment the Dotenv::load() method in your bootstrap/app.php file.

Source: http://lumen.laravel.com/docs/cache

Solution 6 - Php

in your .env file, you can also use CACHE_DRIVER=file instead of CACHE_DRIVER=memcached

Solution 7 - Php

In my case i added Add CACHE_DRIVER=array in .env file
Then

Dotenv::load(__DIR__.'/../');

in my bootstrap/app.php and the .env file started working.

Solution 8 - Php

For me, the issue was that I used the php-7 branch of homestead repository which does not have PHP memcached ready.

Solution 9 - Php

I had a similar problem now, I couldn't track it down but my guess is that it has something to do with the fact that the defaults configurations are stored in the vendor/laravel/lumen-framework/config folder, the DotEnv::$inmutable setting and the artisan serveserver.

The solution that worked for me was:

  1. Add in bootstrap/app.php the following: Dotenv::makeMutable(); Dotenv::load(__DIR__.'/../'); Dotenv::makeImmutable();

  2. in the .env file, set all the configuration to "basic drivers" (array, file) even if you are not going to use them, because you w

Solution 10 - Php

If you have a new lumen installation, you must rename .env.example to .env . So it can read your configurations!

Solution 11 - Php

This happens if your .env file is owned by another user than the one trying to run the artisan command.

Solution 12 - Php

Check if memcached is installed, if not install it by running:

apt-get install php5-memcached

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaul OkekeView Question on Stackoverflow
Solution 1 - Phpw3spiView Answer on Stackoverflow
Solution 2 - PhpAlex OsbornView Answer on Stackoverflow
Solution 3 - PhpAjay KumarView Answer on Stackoverflow
Solution 4 - PhpManoj ThapliyalView Answer on Stackoverflow
Solution 5 - PhpdavidnknightView Answer on Stackoverflow
Solution 6 - PhpS.Hossein AsadollahiView Answer on Stackoverflow
Solution 7 - PhpSajjad AshrafView Answer on Stackoverflow
Solution 8 - PhpJosh LaMarView Answer on Stackoverflow
Solution 9 - PhpdemveView Answer on Stackoverflow
Solution 10 - PhpMasoudView Answer on Stackoverflow
Solution 11 - PhpKarelView Answer on Stackoverflow
Solution 12 - PhpHeinrich BoersView Answer on Stackoverflow