一、下载扩展包及依赖
libmemcached下载地址
https://launchpad.net/libmemc…
php-memcached下载地址 (PHP5.6选择2.2.0版本,PHP7选择3.X版本)
http://pecl.php.net/package/m…
二、安装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
/usr/local/Cellar/php@5.6/5.6.37/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
./configure --enable-memcached --with-php-config=/usr/local/Cellar/php@5.6/5.6.37/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached
make && make install«
Installing shared extensions:/usr/local/Cellar/php@5.6/5.6.37/pecl/20131226
# 然后修改PHP配置文件,添加memcached.so,然后重启nginx即可
vim /usr/local/etc/php/5.6/php.ini
#添加 extension=memcached.so
四、安装容易遇到的问题
根据PHP版本选择对应的扩展(PHP7选择3.X,PHP2-6选择2.X版本)
安装libmemcached过程中不要忘了,–with-memcached
文件写入权限
编译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