macOS Sierra系統下PHP5.6安裝memcached擴充套件

思源發表於2019-02-16

一、下載擴充套件包及依賴

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
/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

四、安裝容易遇到的問題

根據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

相關文章