50

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.

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Paul Okeke
  • 1,384
  • 1
  • 13
  • 19
  • Sorry did you already follow the documentations steps ? http://lumen.laravel.com/docs/authentication – borracciaBlu Apr 22 '15 at 07:01
  • and the cache docs ? http://lumen.laravel.com/docs/cache – borracciaBlu Apr 22 '15 at 07:08
  • could you insert your .env file please? – borracciaBlu Apr 22 '15 at 07:08
  • @lorenz i stated it clearly that i don't want to use memcache, so i really don't know how it answered my question + i don't have enough reputation to downvote you, im sorry twasn't me. – Paul Okeke Apr 22 '15 at 09:03
  • @borraciaBlu trust me i have gone through the documentation.. Please see the edited question – Paul Okeke Apr 22 '15 at 09:17
  • Are you certain this is the correct .env file? – lukasgeiter Apr 22 '15 at 15:10
  • There are two, .env and .env.example, what i use for my db connection is .env and it works. even on the .env.example i placed the same settings just to test, but no luck – Paul Okeke Apr 22 '15 at 16:46
  • Somewhere in your code do `env('SESSION_DRIVER')` and see what it returns... (Oh and also please answer with `@lukasgeiter` so I get a notification ;)) – lukasgeiter Apr 22 '15 at 18:40
  • @lukasgeiter Thanks for the reply... I'm sorta confuse env('SESSION_DRIVER') returns memcached even when its set to cookie in my .env file. – Paul Okeke Apr 23 '15 at 03:00
  • @PaulOkeke Hmmm. Can you comment out the Dotenv::load and then try the same again? – lukasgeiter Apr 23 '15 at 05:46
  • @lukasgeiter Still the same result, It returns memcached. :( – Paul Okeke Apr 23 '15 at 09:54
  • @PaulOkeke That means either for some reason this is set for your environment (and not overridden correctly) or your somehow working with the wrong file(s) Can you tell me a bit about your setup? – lukasgeiter Apr 23 '15 at 09:57
  • 2
    You may need to restart your server, especially if you're using `php artisan serve`. I had exactly the same issue - trying to use file cache, but received errors regarding Memcached - restarting the server reloads the .env. Doesn't appear to pick up changes per-request. – Alex Osborn Apr 24 '15 at 01:37
  • @AlexOsborn ... Yayyy!!! Yay!!!! It Worked.....I shut down and then restarted the server. i mostly do hibernate my system so i don't restart things all the time... Thanks much – Paul Okeke Apr 24 '15 at 09:26
  • @lukasgeiter Thanks for helping as well... Thanks Y' all – Paul Okeke Apr 24 '15 at 09:26
  • Of course!!! (Y) @AlexOsborn Please answer the question so the solution is more visible to others and the question marked as solved :) – lukasgeiter Apr 24 '15 at 09:28
  • Remember to rename .env.example => .env after installing. that was my problem :$ – chesscov77 May 06 '17 at 20:50

12 Answers12

46

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

Andhi Irawan
  • 456
  • 8
  • 15
w3spi
  • 4,380
  • 9
  • 47
  • 80
  • 14
    The term 'solution' is misleading. This is a workaround. You didn't fix memcached, you just use something else. –  Jan 26 '16 at 08:40
20

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.

Alex Osborn
  • 9,831
  • 3
  • 33
  • 44
13

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
Ajay Kumar
  • 1,314
  • 12
  • 22
  • 2
    This indeed should be the best answer, while all other answers are just work-around by using another cache driver. P.S. use `yum install php-memcached -y` in Amazon Linux – Richard Fu Dec 18 '20 at 08:57
  • wow, this happened to me right after doing an apt install upgrade and it turns out that the memcached from php7.3 had been uninstalled for some unknown reason. I tried this solution and recovered the site – Vítor Campos Feb 28 '21 at 18:10
8

In .env file replace

#This line:- 
  CACHE_DRIVER = memcached

#With this:- 
   CACHE_DRIVER = array
Manoj Thapliyal
  • 567
  • 7
  • 9
7

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

davidnknight
  • 462
  • 4
  • 7
4

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

S.Hossein Asadollahi
  • 1,450
  • 2
  • 17
  • 22
2

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.

Sajjad Ashraf
  • 3,754
  • 1
  • 34
  • 35
2

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

Josh LaMar
  • 271
  • 3
  • 7
  • Yeah, this happened to me. You'll have to install the php7 branch of memcached: http://stackoverflow.com/questions/33073141/has-anyone-got-memcached-to-work-on-laravel-homestead-php7-box – prograhammer Oct 30 '15 at 21:57
1

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

demve
  • 216
  • 2
  • 7
  • This seems to work in Lumen 5.2! Can you provide additional info for this solution? Why does this work? What does makeMuteable() do? – kair May 20 '16 at 12:52
  • 1
    MakeMutable set the Dotenv object to override its previous values. – demve Jul 19 '16 at 12:43
-1

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

Masoud
  • 414
  • 4
  • 11
-1

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

Karel
  • 89
  • 1
  • 2
-2

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

apt-get install php5-memcached
Charles
  • 4,372
  • 9
  • 41
  • 80