8

When trying to run artisan commands I get the following error

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Memcached' not found

I had recently been been working on another project that used Lumen 5.3 and had no problem running artisan commands. Both projects are on the same virtual box and apart from the Lumen versions there is no differences in server setup.

I've checked that Memcached is running and there is no problems.

I've tried composer dump-autoload, deleting the vendor folder and re-installing but none of these have made a difference.

I'd prefer not to have to go back to 5.3 if possible.

Is there a way to solve this issue?

Danny Connolly
  • 879
  • 3
  • 10
  • 27

5 Answers5

7

Had the same problem. Check if you have the memcached extension installed for the php version that you're using, and check also if it is correctly configured in the php.ini file (it could be looking in the wrong directory).

6

looks like your memcahed is not installed or not properly configured.

for quick solution ,

use file cache driver instead of memcached

CACHE_DRIVER=file
Mahfuz
  • 467
  • 6
  • 11
2

Ubuntu 16.04 LTS, try this:

sudo apt-get install php-memcached
Pang
  • 9,564
  • 146
  • 81
  • 122
1

Just to add to the os specific responses. Here is the one using OS/X and homebrew.

First you have to determine which version of PHP you're using locally.

$ php -v                
PHP 7.0.19 (cli) (built: May 21 2017 11:56:11) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

$ brew search memcached  
homebrew/php/php53-memcached            homebrew/php/php70-memcached 
homebrew/php/php54-memcached            homebrew/php/php71-memcached
homebrew/php/php55-memcached            libmemcached ✔
homebrew/php/php56-memcached            memcached ✔

Since I'm running PHP 7.0 I chose to install homebrew/php/php70-memcached

$ brew install homebrew/php/php70-memcached

If you don't have homebrew installed go to https://brew.sh/ and install it to use these instructions. This was the command last time I used it.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once I was done with all that then I tested by clearing the cache.

$ php artisan cache:clear
Cache cleared successfully.
$

Cheers, this fixed it for me for local development.

jbrahy
  • 4,228
  • 1
  • 42
  • 54
1

If you are on Mac OSX, you will need to install Memcached and its PHP dependencies via Homebrew.

brew update
brew doctor
brew install memcached

Then check your PHP version and install your relevant PHP hooks for Memcached.

php -v

in my case...

PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

So I used:

brew install php71-memcached

But you can lookup your required version using

brew search memcached

Once you have performed these steps you will probably get a new error

No Memcached servers added.

So fire it up with

brew services restart memcached

Done!

Grant
  • 5,709
  • 2
  • 38
  • 50
  • 2
    Another small tip, if you're using Valet, use `valet restart` after this process, just to restart the php and take the new memcached module into effect. – Grant Oct 29 '17 at 21:18
  • Any idea where to find php71-memcached formulas after brew migrated all to core? – vaske May 25 '18 at 17:30
  • Try this, @vaske - `ln -s /usr/local/opt/php71/bin/php /usr/local/bin/php` – Grant May 28 '18 at 06:11