我正在尝试将 memcached
用于Amazon Linux EC2实例上的PHP。在我的php脚本中,当我调用 $mc = new Memcached();
时,以下错误将在 /var/log/php-fpm/www-error.log
中丢弃:
[06-Sep-2020 00:49:44 UTC] PHP Fatal error: Uncaught Error: Class 'Memcached' not found in /var/app/current/memcached.php:8
Stack trace: #0 {main}
thrown in /var/app/current/memcached.php on line 8
呼叫 php -m
我看不到 memcached
列出,我认为这意味着未安装它。
所以,我首先尝试了:
sudo yum install memcached
sudo yum install php70-pecl-memcached
以及 /etc/php.ini
的编辑
session.save_handler = memcached
session.save_path = "127.0.0.1:11211"
如概述 here ,但没有运气。
因此,接下来,我尝试了AWS支持 here 的Amazon Linux EC2 V1的建议。通过 cfn-init-cmd.log
查看,软件包 libmemcached
已安装了成功,但是,脚本在尝试安装 memcached
时失败,因为它无法根据命令 /use/bin/pecl7
找到 01_install_memcached
。作为参考,我在 .ebextensions/memcache.config
中的完整脚本是:
packages:
yum:
libmemcached-devel: []
commands:
01_install_memcached:
command: /usr/bin/yes 'no'| /usr/bin/pecl7 install memcached
test: '! /usr/bin/pecl info memcached'
02_rmfromphpini:
command: /bin/sed -i -e '/extension="memcached.so"/d' /etc/php.ini
03_createconf:
command: /bin/echo 'extension="memcached.so"' > /etc/php-7.3.d/41-memcached.ini
test: '/usr/bin/pecl7 info memcached'
关于如何解决的任何想法?
我通过直接添加膜到安装来解决此问题