Mac下安装php-memcached扩展
【libmemcached安装】
libmemcached可以通过直接下载后解压也可以采用wget下载
先下载libmemcached:
方式一:libmemcached下载地址:https://launchpad.net/libmemcached/+download
方式二:wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
解压
mkdir -p /usr/local/libmemcached // 遇到权限问题 执行 sudo mkdir -p /usr/local/libmemcached // 输入密码后即可 tar zxvf libmemcached-1.0.18.tar.gz
进入解压包,编译
cd libmemcached-1.0.18 ./configure --prefix=/usr/local/libmemcached --with-memcached // 注意:--with-memcached这个选项一定要加上
安装
make && make install
安装遇到问题
(1)报错1:编译libmemcached时遇到下面错误
libmemcached/byteorder.cc:66:10: error: use of undeclared identifier 'ntohll' return ntohll(value); libmemcached/byteorder.cc:75:10: error: use of undeclared identifier 'htonll' return htonll(value);
2)报错2:
clients/memflush.cc:42:19: error: comparison between pointer and integer ('char *' and 'int') if (opt_servers == false) ~~~~~~~~~~~ ^ ~~~~~ clients/memflush.cc:51:21: error: comparison between pointer and integer ('char *' and 'int') if (opt_servers == false) ~~~~~~~~~~~ ^ ~~~~~
可以按下面步骤修改即可
(1)编辑libmemcached/byteorder.cc文件
sudo vi libmemcached/byteorder.cc 在 #include "libmemcached/byteorder.h" 下面增加以下内容: #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif
(2)编辑clients/memflush.cc文件
sudo vi clients/memflush.cc 将两处 if (opt_servers == false) 替换成 if (opt_servers == NULL)
(3)如果最后还是提示Permission denied问题,就直接设置安装目前的权限
sudo chmod 777 -R [你自己的文件夹名]
【php-memcached安装】
方式一 php-memcached下载地址:http://pecl.php.net/package/memcached
(PHP5.6选择2.2.0版本,PHP7选择3.X版本)
方式二 : wget https://pecl.php.net/get/memcached-3.1.3.tgz
解压并安装:
tar zxvf memcached-3.1.3.tar cd memcached-3.1.3 // 执行phpize命令生成configure建立php外挂模块 /usr/local/Cellar/php/7.2.12_2/bin/phpize ./configure --with-php-config=/usr/local/Cellar/php/7.2.12_2/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached make && make install
// 修改php.init增加如下代码
#添加 extension=memcached.so