lnmp1.5安装memcache

1.安装libevent

由于Memcache用到了libevent这个库用于Socket的处理,所以需要安装libevent。

# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
# tar zxvf libevent-1.2.tar.gz
# cd libevent-1.2
# ./configure --prefix=/usr/local
# make && make install

  • 出错原因: 在 event.c 文件中 CLOCK_MONOTONIC 没有定义.
  • 解决办法 : 在网上搜了下, 是缺少头文件了, CLOCK_MONOTONIC 定义在 time.h 头文件中. 所以可以直接修改源码:
    在 event.c 中引用头文件: #include <time.h> :
/* 直接在event.c文件最上面include time.h 就可以了. /
#include <time.h>
/ 以下是源码, 不用管! */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
make && make install

测试libevent是否安装成功

ls -al /usr/local/lib | grep libevent

2.安装memcached

# wget http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
# tar zxvf memcached-1.2.5.tar.gz
# cd memcached-1.2.5
# ./configure --prefix=/usr/local/memcache/ --with-libevent=/usr/local/bin
# make && make install

安装完成后会把memcached放到 /usr/local/bin/memcached ,

测试memcached是否安装成功

ls -al /usr/local/bin/memcached

3.安装Memcache的PHP扩展

下载php7的memcache扩展 https://github.com/websupport-sk/pecl-memcache/archive/php7.zip

# yum install -y unzip zip
# unzip pecl-memcache-php7.zip
# cd pecl-memcache-php7
# phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
# vim /usr/local/php/etc/php.ini
   extension=/usr/local/php/lib/php/extensions/no-debug-zts-20170718/memcache.so

 4.重启服务,查看是否安装成功

lnmp restart

原文地址:https://www.cnblogs.com/zouke1220/p/9521979.html