本文章為各位介紹解決編譯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