错误消息:“MemCache需要加载PHP memcache扩展。”迁移后。

时间:2017-06-02 18:18:35

标签: php yii2 memcached

来自phpinfo(): phpinfo, memcache is loaded

但是,当我尝试迁移时,请显示以下错误:

Exception 'yii\base\InvalidConfigException' with message 'MemCache requires PHP memcache extension to be loaded.'

in /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/caching/MemCache.php:217

Stack trace:
#0 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/caching/MemCache.php(113): yii\caching\MemCache->getMemcache()
#1 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/base/Object.php(107): yii\caching\MemCache->init()
#2 [internal function]: yii\base\Object->__construct(Array)
#3 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->newInstanceArgs(Array)
#4 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build('yii\\caching\\Mem...', Array, Array)
#5 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('yii\\caching\\Mem...', Array, Array)
#6 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::createObject(Array)
#7 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/db/Schema.php(275): yii\di\ServiceLocator->get('cache', false)
#8 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/db/Migration.php(71): yii\db\Schema->refresh()
#9 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/base/Object.php(107): yii\db\Migration->init()
#10 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/console/controllers/MigrateController.php(113): yii\base\Object->__construct(Array)
#11 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(491): yii\console\controllers\MigrateController->createMigration('m170316_221710_...')
#12 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(129): yii\console\controllers\BaseMigrateController->migrateUp('m170316_221710_...')
#13 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#14 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#15 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#16 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->runAction('', Array)
#17 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAction('', Array)
#18 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/console/Application.php(167): yii\base\Module->runAction('migrate', Array)
#19 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/console/Application.php(143): yii\console\Application->runAction('migrate', Array)
#20 /Library/WebServer/Documents/r2d2/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
#21 /Library/WebServer/Documents/r2d2/yii(27): yii\base\Application->run()
#22 {main}

有人可以帮我找出原因吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

错误来自控制台应用程序,phpinfo输出来自webserver。所以,你基本上为webserver启用了memcache模块,但没有为控制台启用。要提供准确的解决方案,需要有关您的设置的更多信息:您使用什么,php-fpm,modapache?请从web和cli

提供完整的phpinfo输出

<强>更新

检查控制台PHP扫描哪些目录以获取其他ini文件:

php -i | grep "Scan this dir for additional .ini files"

然后,您需要将配置文件(例如memcache.ini)与模块配置放入其中一个。内容应该是:

extension=memcache.so

您可以检查一个网络服务器用于参考。

答案 1 :(得分:0)

如果使用memcached代替memcache,则需要将此行添加到config / console.php:

'useMemcached' => true,

它应该像这样:

'components' => [
    'cache' => [
        'class' => 'yii\caching\MemCache',
        'useMemcached' => true,
        'servers' => [
            [

....