解決編譯php memcached擴充的問題:php

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.