macOS Sierra系统下PHP5.6安装memcached扩展

一、下载扩展包及依赖

libmemcached下载地址
https://launchpad.net/libmemcached/+download

php-memcached下载地址 (PHP5.6选择2.2.0版本,PHP7选择3.X版本)
http://pecl.php.net/package/memcached

二、安装libmemcached依赖

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
make && make install

注:涉及创建文件夹及写入文件等操作,需有对应权限,本文其他地方不再赘述。

三、安装memcached扩展 (本文以XAMPP环境为例,具体安装时需要根据自己PHP安装路径来定)

mkdir -p /usr/local/phpmemcached
tar zxvf memcached-2.2.0.tgz
cd memcached-2.2.0
/Applications/XAMPP/xamppfiles/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226

./configure --enable-memcached --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached
make && make install
Installing shared extensions:/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226

然后修改PHP配置文件,添加memcached.so,然后重启Apache即可

vi /Applications/XAMPP/xamppfiles/etc/php.ini
添加 extension=memcached.so

四、安装容易遇到的问题

  1. 根据PHP版本选择对应的扩展(PHP7选择3.X,PHP2-6选择2.X版本)
  2. 安装libmemcached过程中不要忘了,–with-memcached
  3. 文件写入权限
  4. 编译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);

可以按下面步骤修改即可

编辑libmemcached/byteorder.cc文件

sudo vi libmemcached/byteorder.c,在 #include "libmemcached/byteorder.h" 下面增加,以下内容:

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

保存退出

configure时报错

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)
~~~~~~~~~~~ ^ ~~~~~

编辑clients/memflush.cc
sudo vi clients/memflush.cc,将两处if(opt_servers == false)里面的false改为NULL

发表评论

电子邮件地址不会被公开。 必填项已用*标注