centos 7.4 安装memcached以及php memcached扩展

时间:2021-05-21 20:42:00

1.由于Memcached依赖libevent 库,用它做Socket的处理,因此,我们需要安装libevent库

yum -y install libevent

yum install libevent-devel


2.下载memcached-1.5.0.tar.gz

tar -zxvf memcached-1.5.0.tar.gz

cd /home/memcached-1.5.0

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

make && make install


3.启动memcached

cd /usr/local/memcached/bin

./memcached -d -m 2048 -l 127.0.0.1 -p 11211 -u root -c 1024 -p /var/memcached/memcached.pid -vv


4.下载php memcached扩展需要的包

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

wget https://pecl.php.net/get/memcached-2.2.0.tgz


5.安装libmemcached

tar -zxvf libmemcached-1.0.18.tar.gz

cd libmemcached-1.0.18

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

make && make install


6.安装php-memcached 

tar -zxvf memcached-2.2.0.tgz

cd memcached-2.2.0

phpize  //显示没有安装phpize

yum install php-devel  //安装phpize

phpize

出现如下信息说明安装成功

Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525

Zend Extension Api No:   220100525

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

make 

make install

出现如下信息说明安装成功

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


7.修改php.ini

vim /usr/local/php/lib/php.ini

在END前加上extension=memcached.so;

重启php-fpm

注意:如果发现找不到php.ini文件,解决方法:
去原php的源码目录(就是刚开始下载的php压缩包)查看php.ini-development或php.ini-production
再当前环境选择将哪个文件重命名为php.ini
并同时将php.ini文件复制到phpinfo()中php.ini所在的目录中即可
(在phpinfo里面搜索php.ini,查看php.ini应该在哪个路径)