如何在Linux下安装php-memcached扩展

来源:互联网 发布:影视会员源码 编辑:程序博客网 时间:2024/05/29 13:07

在Linux下的php memcached扩展叫做memcached.so,安装memcached.so有两种方式,一种是使用源码编译安装、一种是使用PECL安装。

安装完此扩展后,PHP才能和memcache或者memcached通讯。(memcache 和 memcached为缓存服务器。memcache是原生的,memcached需要依赖

由于memcached.so扩展需要依赖libmemcached包,所以无论以哪种方式安装,都必须先安装libmemcached包。

  1. 源码编译安装libmemcached
    • yum install libevent-devel (安装前,需要先安装libevent-devel,要不然总是报错,不知道为什么,百度得知此解决方案
    • wget http://launchpad.net/libmemcached/1.0/1.0.6/+download/libmemcached-1.0.6.tar.gz
    • tar  -zxvf  libmemcached-1.0.6.tar.gz
    • cd libmemcached-1.0.6
    • ./configure --prefix=/usr/local/libmemcached --with-memcached
    • make && make install
    • 安装完之后可以用memstat -h进行测试,如果出现了帮助说明,说明安装成功。

  2. PECL安装php-memcached扩展 
    • 【安装】pecl install memcached,一路回车即可。

  3. 源码编译安装
    • wget http://pecl.php.net/get/memcached-2.1.0.tgz
    • tar  -zxvf  memcached-2.1.0.tgz
    • cd memcached-2.1.0
    • /usr/local/php/bin/phpize   (此步骤是与安装软件包不同之处,安装php扩展必须phpize
    • ./configure --with-php-config=/user/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached
    • make && make install
    • 【安装成功后如下图,在红圈处的目录中会生成memcached.so】

至此,php-memcached扩展安装成功,需要配置php.ini,加入memcached.so扩展,重启php即可。运行phpinfo(),可以看到如下:


0 0