升级 php7.3 后 Memcached 报错的解决办法


需要安装编译工具、libevent 和  libmemcached

#  Ubuntu
apt -y install gcc autoconf m4 automake build-essential
apt -y install zlib1g zlib1g-dev libpcre3 libpcre3-dev openssl libssl-dev rng-tools
apt -y install memcached libevent-dev libmemcached-tools libmemcached11 libmemcached-dev

# CentOS
yum -y groupinstall "Development libraries" "Development tools"
yum -y install libtool libev-devel openssl-devel ca-certificates gpgme-devel rng-tools
yum -y install autoconf m4 zlib zlib-devel
yum -y install memcached libmemcached libmemcached-devel

wget https://pecl.php.net/get/memcached-3.1.4.tgz
tar zxvf memcached-3.1.4.tgz
cd memcached-3.1.4
/opt/lampp/bin/phpize
./configure  --with-libmemcached-dir --enable-memcached --with-php-config=/opt/lampp/bin/php-config --disable-memcached-sasl
make && make install

wget https://github.com/websupport-sk/pecl-memcache/archive/4.0.4.zip
unzip 4.0.4.zip
cd pecl-memcache-4.0.4
/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config
make && make install

mkdir /opt/lampp/ext
/bin/cp -rf /opt/lampp/lib/php/extensions/no-debug-non-zts-20180731/* /opt/lampp/ext

816 行左右  vim /opt/lampp/etc/php.ini

extension_dir=/opt/lampp/ext/
extension=memcached.so
extension=memcache.so

# 查看是否加载了该模块
/opt/lampp/bin/php -m

# 重启APACHE
/opt/lampp/lampp restartapache

# memcached -d -m 64 -l 127.0.0.1 -p 11211


=====================================

Fatal error: Uncaught Error: Class 'Memcached' not found

用 pecl install memcache memcached
报错: make: *** [memcache.lo] Error 1

在 php.net 上搜索的结果 

https://www.php.net/manual/zh/memcache.installation.php
https://www.php.net/manual/zh/memcached.installation.php

下载 memcache 和 memcached
wget https://pecl.php.net/get/memcache-3.0.8.tgz
wget https://pecl.php.net/get/memcached-3.1.4.tgz


先安装 yum -y install libmemcached libmemcached-devel

--------------------------------------
tar zxvf memcached-3.1.4.tgz
cd memcached-3.1.4
/opt/lampp/bin/phpize
./configure --enable-memcached --with-php-config=/opt/lampp/bin/php-config --with-libmemcached-dir=/usr/lib/libmemcached --disable-memcached-sasl
make && make install

--------------------------------------
编译 memcache,这里不用pecl上文件
wget https://github.com/websupport-sk/pecl-memcache/archive/4.0.4.zip
unzip 4.0.4.zip
/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config
make && make install

--------------------------------------
在 php.ini 中加载模块
/bin/cp -rf /opt/lampp/lib/php/extensions/no-debug-non-zts-20180731/* /opt/lampp/ext/

816 行左右  vim /opt/lampp/etc/php.ini

extension_dir=/opt/lampp/ext/
extension=memcached.so
extension=memcache.so

--------------------------------------
安装 Memcached
据说是 要先安装 安装libevent
http://www.memcached.org/files/memcached-1.5.20.tar.gz
tar -zxvf memcached-1.5.20.tar.gz
cd memcached-1.5.20
./configure --prefix=/usr/local/libmemcached  --with-memcached
#./configure
make && make test && sudo make install

--------------------------------------
参考资料
https://blog.csdn.net/cpj555/article/details/52452618
http://www.mamicode.com/info-detail-2326326.html

Memcached 安装以及安装php扩展
https://blog.csdn.net/woshihaiyong168/article/details/54288708




从pecl用以下方法编译到的memcache.so文件无效

make 之后,报错: make: *** [memcache.lo] Error 1 ,需要 memcache.loT 改名为 memcache.lo
再次编译对待类似的报错还是这样处理,直到编译安装完成

tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8

# 循环执行下面的命令,直到编译完成

fn=`ls *.loT` && name=${fn%.*}
mv $fn $name.lo
/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config --enable-memcache
make && make install