解决编译php memcached扩展的问题:php_libmemcached_compat.h:5:40

服务器是Centos6 64,PHP5.4.23,需要安装php memcached扩展

尝试使用pecl安装:
# yum install libmemcached libmemcached-devel zlib-devel
# yum -y install php-pear
# pecl install memcached

但出现错误:
在包含自 /var/tmp/memcached/php_memcached.h:22 的文件中,从 /var/tmp/memcached/php_memcached.c:47:
/var/tmp/memcached/php_libmemcached_compat.h:5:40: 错误:libmemcached-1.0/memcached.h:没有那个文件或目录

上面明显php_libmemcached_compat.h文件中找不到memcached.h,于是下载文件包,一看究竟:
# wget http://pecl.php.net/get/memcached
# mv memcached memcached.tar.gz
# tar zxf memcached.tar.gz
# cd memcached-2.2.0b1/
# vi php_libmemcached_compat.h
 17 #ifndef PHP_LIBMEMCACHED_COMPAT
 18 #define PHP_LIBMEMCACHED_COMPAT
 19
 20 /* this is the version(s) we support */
 21 #include <libmemcached/memcached.h>

看到上面包含libmemcached/memcached.h,但事实上memcached.h文件位于:
# find /usr -name memcached.h
/usr/include/libmemcached/memcached.h

那么修改上面的路径为正常路径:

 17 #ifndef PHP_LIBMEMCACHED_COMPAT
 18 #define PHP_LIBMEMCACHED_COMPAT
 19
 20 /* this is the version(s) we support */
 21 #include </usr/include/libmemcached/memcached.h>

保存后,使用phpize来编译:

configure: error: no, sasl.h is not available. Run configure with --disable-memcached-sasl to disable this check
cyrus-sasl-devel

只好加上 --disable-memcached-sasl,重新进行,但依然出现错误:
# ./configure --disable-memcached-sasl
...省略...
In file included from /root/download/memcached-2.2.0b1/php_memcached_private.h:28,
                 from /root/download/memcached-2.2.0b1/php_memcached.c:26:
/root/download/memcached-2.2.0b1/php_libmemcached_compat.h:53: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘php_memcached_instance_st’
...省略...

看来此路不通,只有手动编译libmemcached来尝试了。

下面是手动编译libmemcached和php memcached扩展

1. 先卸载yum安装的libmemcached

# yum remove libmemcached libmemcached-devel

2. 下载源码包

# cd ..
# wget https://launchpad.net/libmemcached/1.0/1.0.17/+download/libmemcached-1.0.17.tar.gz
# tar zxf libmemcached-1.0.17.tar.gz
# cd libmemcached-1.0.17
# ./configure
# make
# make install

成功安装libmemcached。

3. 接下来安装memcached,先查找memcached.h头文件在哪里,需要在php_libmemcached_compat.h设置正确的include路径

# cd ../memcached-2.2.0b1
# find / -name memcached.h
/root/download/libmemcached-1.0.17/libmemcached/memcached.h
/root/download/libmemcached-1.0.17/libmemcached-1.0/struct/memcached.h
/root/download/libmemcached-1.0.17/libmemcached-1.0/memcached.h
/root/download/libmemcached-1.0.17/libtest/memcached.h
/root/download/mysql-5.6.15/plugin/innodb_memcached/daemon_memcached/daemon/memcached.h
/usr/local/include/libmemcached/memcached.h
/usr/local/include/libmemcached-1.0/struct/memcached.h
/usr/local/include/libmemcached-1.0/memcached.h

4. 修改memcached-2.2.0b1下的php_libmemcached_compat.h文件中include路径为正确路径:

 17 #ifndef PHP_LIBMEMCACHED_COMPAT
 18 #define PHP_LIBMEMCACHED_COMPAT
 19
 20 /* this is the version(s) we support */
 21 #include </usr/local/include/libmemcached/memcached.h>

5. 开始编译安装php memcached扩展:

# phpize
# ./configure
# make
...省略...
Build complete.
Don't forget to run 'make test'.
 
# make install
Installing shared extensions:     /usr/lib64/php/modules/

6. 查看是否已生成了memcached.so:

# ls /usr/lib64/php/modules/
bcmath.so    gd.so        memcached.so         mysql.so       phar.so     sysvsem.so  xcache.so     xsl.so
curl.so      json.so      memcache.so          pdo_mysql.so   posix.so    sysvshm.so  xmlreader.so  zip.so
dom.so       mbstring.so  mysqli.so            pdo.so         sqlite3.so  tidy.so     xmlrpc.so
fileinfo.so  mcrypt.so    mysqlnd_memcache.so  pdo_sqlite.so  sysvmsg.so  wddx.so     xmlwriter.so

时间: 2024-10-02 17:08:22

解决编译php memcached扩展的问题:php_libmemcached_compat.h:5:40的相关文章

解决编译php memcached扩展的问题:php

 本文章为各位介绍解决编译php memcached扩展的问题:php_libmemcached_compat.h:5:40: 错误:libmemcached-1.0/memcached.h:没有那个文件或目录,希望文章对各位有帮助.     服务器是Centos6 64,PHP5.4.23,需要安装php memcached扩展 尝试使用pecl安装: # yum install libmemcached libmemcached-devel zlib-devel # yum -y insta

编译安装memcached扩展记要

编译memcached扩展的时候,得指定libmemcached库的位置 --with-libmemcached-dir=DIR 来指定路径.这个路径就是安装libmemcached时指定的prefix的值 所以得先安装libmemcached库. 一.安装libmemcached库 libmemcached库为什么编译不成功,好像是需要更高版本的gcc编译器?我按照网上说的,执行了: yum install gcc44 gcc44-c++ libstdc++44-devel 原因 貌似是gcc

编译安装Memcached 和 Memcache 的PHP扩展

一:安装Memcache 1:编译安装libevent wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar -zxvf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure --prefix=/usr/local/libevent make make isntall 2:编译安装memcached

linux下编译安装Memcached 和 Memcache 的PHP扩展

一:安装Memcache 1:编译安装libevent wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar -zxvf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure --prefix=/usr/local/libevent make make isntall 2:编译安装memcached

注意!PHP memcached扩展默认配置下无法自动failover

最近项目中用到PHP连接Memcache的场景.这个场景对于PHP开发者很常见.但就是这么常见的一个场景,带来了意想不到的一个问题. 我这边的php memcached扩展版本是: memcached MEMCACHED SUPPORT ENABLED Version 2.1.0 libmemcached version 1.0.8 Session support yes igbinary support no json support no 案例如下: 在本地服务器启动两个memcache实例

Windows下编译安装php扩展eAccelerator教程_win服务器

eAccelerator是一个开源PHP加速器,用于优化程序,编码器和动态内容缓存.它通过在编译状态下对PHP脚本进行缓存以提高他们的性能,所以那些系统开销在编译时几乎可以被消除.它还能够对脚本进行优化以便加速它们的执行速度.利用eAccelerator可以减少服务器的负载并提高PHP代码的执行效率. 一.前期准备 1.下载php原代码和二进制包 地址:http://windows.php.net/download/ 2.下载eaccelerator(选择zip包) 地址:http://eacc

memcache与memcached扩展的区别

一.服务端 之前理解错误了.服务端只有一个memcache,一般把服务端称作memcached(带d),是因为守护进程的名称就是叫做memcached(一个这样的执行程序文件).   编写的语言:c语言 官网为:http://memcached.org/    二.客户端   很多人都面对两个php的扩展大有疑惑,而且也记不住,只是知道memcached扩展更加高级嘛. 其实,我觉得,只要了解c语言的两个库的区别,就能知道了本质区别了. 既然要操作服务端,那么就要有客户端来操作.memcache

PHP安装memcached扩展笔记

  这篇文章主要介绍了PHP安装memcached扩展笔记,本文讲解了安装服务端.launchpad.安装memcached扩展以及配置PHP.ini等内容,需要的朋友可以参考下 最近在服务器上部缓存系统,记录一下PHP安装memcached扩展. 代码如下: # 安装服务端 yum install memcached -y I. launchpad 请于https://launchpad.net/libmemcached/+download下载目前最新版的libmemcached(201505

解决编译imagick-3.0.1时Cannot locate header file MagickWand.h错误

解决编译imagick-3.0.1时Cannot locate header file http://www.aliyun.com/zixun/aggregation/16764.html">MagickWand.h错误 ImageMagick 6.8之后的版本目录结构改变了,我们查询到ImageMagick的结果如下 [root@localhost ~]# ll /usr/local/include/总用量 48-rw-r--r--. 1 root root  9343 6月   8 1