hkt1998

hkt1998

宝塔PHP安装扩展memcached失败

2024-02-26

使用宝塔自带的php扩展安装功能,安装memcached失败,截取报错信息最后一段:

checking whether to enable memcached msgpack serializer support... no
checking whether to enable memcached sasl support... yes
checking whether to enable memcached protocol support... no
checking whether to use system FastLZ library... no
checking for ZLIB... yes, shared
checking for pkg-config... /bin/pkg-config
checking for zlib location... /usr
checking for session includes... /www/server/php/82/include/php
checking for memcached session support... enabled
checking for memcached igbinary support... disabled
checking for memcached msgpack support... disabled
checking for libmemcached location... configure: error: Unable to find memcached.h under /usr/local/libmemcached
make: *** No targets specified and no makefile found. Stop.
Install failed

关键信息是后面这一句:

checking whether to enable memcached msgpack serializer support... no
checking whether to enable memcached sasl support... yes
checking whether to enable memcached protocol support... no
checking whether to use system FastLZ library... no
checking for ZLIB... yes, shared
checking for pkg-config... /bin/pkg-config
checking for zlib location... /usr
checking for session includes... /www/server/php/82/include/php
checking for memcached session support... enabled
checking for memcached igbinary support... disabled
checking for memcached msgpack support... disabled
checking for libmemcached location... configure: error: Unable to find memcached.h under /usr/local/libmemcached
make: *** No targets specified and no makefile found. Stop.
Install failed

意思是在/usr/local/libmemcached这个路径下找不到memcached.h文件。

我看了下确实没有这个目录,使用yum命令安装了libmemcachedlibmemcached-devel依然没有这个目录。

看到网上说需要编译安装,而且yum上的版本只到1.0.16,最新版是1.0.18,我也不清楚是安装方式的问题还是版本的问题,但是我通过编译安装1.0.18版本的libmemcached后,问题解决了。

安装过程

获取源码包

可以通过wget下载,但我安装的时候这个网站超时响应。

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

也可以到这个网站直接下载:https://launchpad.net/libmemcached/+download

解压

tar -xzvf libmemcached-1.0.18.tar.gz

此处如果解压参数给的是zxvf的话,会遇到报错

tar: Old option 'f' requires an argument

顺便温习一下Linux的tar指令

编译安装

# 进入目录
cd libmemcached-1.0.18

# 配置libmemcached和memcached的安装路径
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached

# 编译安装
make && make install

安装完成后可以在/usr/local目录下看到libmemcached文件夹啦。

然后就是使用宝塔的php扩展安装功能,即可成功装上memcached扩展。