macos安裝memcached及PHP擴展

首先安裝memcached

brew install memcached

由於PHP對memcached的支持是由基於libmemached的PHP memcached擴展實現的,首先到https://libmemcached.org/libMemcached.html下載llibmemcached包。
解壓後進入文件夾進行編譯

./configure
make

接下來問題來了,編譯過程中會出現兩個error

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

#include "mem_config.h"
#include "libmemcached/byteorder.h"

後面加上

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

這時make clean一下,清除上次make產生的文件,再次make
這時會出現另一個error

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中的兩處opt_servers == false的false改成NULL
一般來說改了這兩處就沒有其他問題了,如此修改的原因參見https://blog.longqiuhong.com/archives/132
接下來

make clean
make
make install

等待滾屏。

libmemcached安裝完成,接下來安裝php-memcached擴展
網上有些文章使用自行下載memcached擴展包然後編譯安裝的方式,比較麻煩,這裏使用更簡單的方法

pecl install memcached

pecl是一個PHP擴展庫,使用pear的包管理器,可以幫助我們快速安裝php擴展
接下來,pecl將會詢問libmemcached的所在路徑,如果安裝正確,輸入/usr/local就可以自動地安裝好memcached擴展了。
如果之前的編譯安裝沒成功,可能會提示找不到memcached.h這時需要重複嘗試

make clean
make 
make install
pecl install memcached

筆者也是嘗試了幾次才成功。

接下來開啓我們的memcached服務

brew services start memcached

查看memcached監聽的端口,一般是11211

lsof | grep memcached

其中有兩行最後標有(LISTEN)字樣,這裏的端口號就是memcached監聽的端口了。
到這裏安裝工作圓滿完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章