技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁(yè) > 教程 > 服務(wù)器類 >

解決編譯php memcached擴(kuò)展的問(wèn)題:php_libmemcached_compat.h:5:40

來(lái)源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2018-05-03 00:21┆點(diǎn)擊:

服務(wù)器是Centos6 64,PHP5.4.23,需要安裝php memcached擴(kuò)展

嘗試使用pecl安裝:
# yum install libmemcached libmemcached-devel zlib-devel
# yum -y install php-pear
# pecl install memcached

但出現(xiàn)錯(cuò)誤:
在包含自 /var/tmp/memcached/php_memcached.h:22 的文件中,從 /var/tmp/memcached/php_memcached.c:47:
/var/tmp/memcached/php_libmemcached_compat.h:5:40: 錯(cuò)誤:libmemcached-1.0/memcached.h:沒(méi)有那個(gè)文件或目錄

上面明顯php_libmemcached_compat.h文件中找不到memcached.h,于是下載文件包,一看究竟:
# wget
# 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,但事實(shí)上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來(lái)編譯:

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

只好加上 --disable-memcached-sasl,重新進(jìn)行,但依然出現(xiàn)錯(cuò)誤:
# ./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: 錯(cuò)誤:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘php_memcached_instance_st’
...省略...

看來(lái)此路不通,只有手動(dòng)編譯libmemcached來(lái)嘗試了。

下面是手動(dòng)編譯libmemcached和php memcached擴(kuò)展

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. 接下來(lái)安裝memcached,先查找memcached.h頭文件在哪里,需要在php_libmemcached_compat.h設(shè)置正確的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. 開(kāi)始編譯安裝php memcached擴(kuò)展:

# 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