解决编译php memcached扩展的问题:php_libmemcached_compat.h:5:40
08-21
本文章为各位介绍解决编译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 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
- • LAMP平台安装Xcache和Memcached加速网站运行
- • CentOS(x86_64)下PHP安装memcache扩展问题解决方法分享
- • LNMP服务器环境配置详解
- • 阿里云PHP环境
- • memcached安装在windows7上的问题及解决方法
- • centos5 源码安装Nginx + mysql + apache + php的方法
- • APMServ一键快速搭建Apache+PHP+MySQL+Nginx+Memcached+ASP运行平台教程
- • PHP5.5在windows使用memcached服务端的方法
- • Centos5.2配置LAMP与Centos5.3配置LAMP