美文网首页
安装memcached

安装memcached

作者: 我的楼兰0909 | 来源:发表于2018-12-10 09:58 被阅读0次

    Linux(centos)为php7安装memcached扩展

    搞这个扩展用了不少时间,之前都是非常快的安装上了。网上搜索了不少文章,多数都是东抄西抄,没法解决问题。

    综合了几个文章,终于搞定,这里记录下步骤:

    1,安装memcached

    yum -y install memcached

    安装完以后执行如下操作:

    chkconfig memcached on

    /etc/init.d/memcached start

    执行

    netstat -tunlp | grep memcached

    看到11211端口,说明memcached安装成功。

    2,安装libmemached

    wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz

    tar -zxvf libmemcached-1.0.16.tar.gz

    cd libmemcached-1.0.16

    ./configure -prefix=/usr/local/libmemcached -with-memcached

    make && make install

    3,下载memcache扩展包并安装

    git clone git://github.com/php-memcached-dev/php-memcached.git

    cd php-memcached/

    安装扩展

    /usr/local/php/bin/phpize

    ./configure -enable-memcached -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir -with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/phpmemcached --disable-memcached-sasl

    make -j4

    make install

    安装完毕后会提示扩展目录:/usr/local/php/lib/php/extensions/no-debug-zts-20151012/

    编辑php.ini:

    extension=/usr/local/php/lib/php/extensions/no-debug-zts-20151012/memcached.so

    将其放入最后一行,重启php服务器(通过组件调用的,重启下web服务)

    重新查看phpinfo:

    Linux下安装php的memcached扩展(memcache的客户端)

    php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached

    一、下载软件

    1、libmemcached下载地址:https://launchpad.net/libmemcached/+download

    https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz

    文件:libmemcached-1.0.18.tar.gz

    2、memcached下载地址:http://pecl.php.net/package/memcached

    http://pecl.php.net/get/memcached-2.2.0.tgz

    文件:memcached-2.2.0.tgz

    二、安装libmemcached

    [root@localhost src]# tar zxvf libmemcached-1.0.18.tar.gz

    [root@localhost src]# cd libmemcached-1.0.18

    [root@localhost libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached

    [root@localhost libmemcached-1.0.18]# make

    [root@localhost libmemcached-1.0.18]# make install

    三、安装php-memcached(php扩展编译的通用办法,以memcached为例)

    [root@localhost src]# tar zxvf memcached-2.2.0.tgz

    [root@localhost src]# cd memcached-2.2.0

    [root@localhost memcached-2.2.0]# /usr/local/php/bin/phpize

    Configuring for:

    PHP Api Version: 20131106

    Zend Module Api No: 20131226

    Zend Extension Api No: 220131226

    [root@localhost memcached-2.2.0]# ./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached

    【编译时可能会出错'configure: error: no, sasl.h is not available'--------解决方法:需要安装libsasl2 ubuntu下用sudo apt-get install libsasl2-dev

    也有可能需要在编译参数中添加--disable-memcached-sasl

    [root@localhost memcached-2.2.0]# make

    [root@localhost memcached-2.2.0]# make install

    Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

    [root@localhost memcached-2.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

    total 2140

    -rwxr-xr-x. 1 root root 325608 Dec 30 15:59 memcached.so

    -rwxr-xr-x. 1 root root 540834 Dec 19 15:38 opcache.so

    [root@localhost memcached-2.2.0]#cp -p /usr/local/src/php-5.6.30/php.ini-development ./php.ini 【因为此时/usr/local/php/lib/下不存在php.ini】

    [root@localhost memcached-2.2.0]# vim /usr/local/php/lib/php.ini

    加上

    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012"

    extension=pdo.so

    extension=pdo_mysql.so

    extension=memcached.so

    重启apache

    [root@localhost memcached-2.2.0]#/usr/local/httpd/bin/apachectl restart

    查看phpinfo可以看到支持了,说明memcached扩展已成功安装!

    寻找PHP加载php.ini文件目录的技巧:

    1.可以使用phpinfo()函数打印并查看(Configuration File (php.ini) Path)信息

    2.如果此目录下没有php.ini配置文件,可以到php安装包中复制一份到此目录下(安装包php配置文件的命名是php.ini-development)

    g++: command not found的解决

    centos:

    yum -y update gcc

    yum -y install gcc+ gcc-c++

    相关文章

      网友评论

          本文标题:安装memcached

          本文链接:https://www.haomeiwen.com/subject/wxkthqtx.html