標籤:
一 安裝libevent
1.去官網http://libevent.org/ 下載最新源碼,我用的是libevent-2.0.20-stable.tar.gz
2.解壓到/usr/src目錄 ,執行命令:sudo tar -zxvf libevent-2.0.20-stable.tar.gz -C /usr/src
3.進入解壓以後的目錄,用sudo方式執行命令:sudo ./configure --prefix=/usr/local/libevent ; make ; make install
二 安裝memcache
1.去官網 http://memcached.org/ 下最新源碼,我用的是memcached-1.4.15.tar.gz
2.解壓到/usr/src目錄 ,執行命令:sudo tar -zxvf memcached-1.4.15.tar.gz -C /usr/src
3.進入解壓以後的目錄,用sudo方式執行命令:sudo ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent; make ; make install
三 安裝php的memcache擴充
有兩個版本一個是memcache(http://pecl.php.net/package/memcache ),另一個是基於libmemcached的memcached版本(http://pecl.php.net/package/memcached );
網上查的資料是說前一個是原生的,後一個比前一個功能更強大。比較推薦使用基於libmemcahced 庫的memcached擴充。支援memcache提供的CAS操作,穩定性和效率也更好。
這裡我使用基於libmemcached 庫的memcached擴充,安裝步驟如下:
首先,安裝libmemcached庫
1.去網址 https://launchpad.net/libmemcached (或者http://libmemcached.org/libMemcached.html )下載源碼,
我用的是libmemcached-1.0.14.tar.gz
2.解壓縮到/usr/src目錄,用sudo方式執行命令:sudo tar -zxvf libmemcached-1.0.14.tar.gz -C /usr/src
3.進入目錄/usr/src/libmemcached-1.0.14/,sudo方式執行命令:./configure ;make;make install (不加--prefix=/usr/local/libmemcached 指定安裝目錄時,libmemcached 預設安裝在/usr/local/,標頭檔安裝在/usr/local/include/libmemcachde/,動態庫預設安裝在/usr/local/lib/下。)
4.make時遇到問題:sorry, unimplemented: Graphite loop optimizations can only be used if the libcloog-ppl0 package is installed。解決辦法是修改Makefile,尋找並去掉 floop-parallelize-all(應該有兩處需要去掉),看了網上資料說是去掉後表示不使用Graphite loop 最佳化。
5.再次make,遇到問題:fatal error: sasl/sasl.h: No such file or directory. 在網上搜到的解決辦法是:
Depending on your operating system, you‘ll need to install the cyrus-sasl development package.
That would be cyrus-sasl-devel on RedHat based distros and libsasl2-dev on Debian based distros IIRC.
我在ubuntu下直接用sudo apt-get install libsasl2-dev 安裝了。
6.編譯還是遇到問題,顯示無法連結到sasl的一些檔案。問題顯示如下:
undefined reference to `sasl_client_step‘
undefined reference to `sasl_dispose‘
undefined reference to `sasl_client_start‘
undefined reference to `sasl_client_new‘
解決辦法是重新執行configure命令,增加相應的參數。sudo執行命令:sudo ./configure --enable-sasl --without-memcached LDFLAGS=-Wl,--as-neede ;make; make install
7.終於安裝libmemcached庫成功了。。。
其次,安裝memcached版本的php擴充
1. 去網址http://pecl.php.net/package/memcached 下載memcached版本,我用的是memcached-2.1.0.tgz
2. 解壓到/usr/src目錄 ,執行命令:sudo tar -zxvf memcached-2.1.0.tgz -C /usr/src
3. 進入解壓以後的目錄,是沒有configure檔案的,用sudo方式執行命令來產生:sudo /usr/local/php/bin/phpize
4.遇到問題:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. 網上搜到的解決辦法為:
cd /usr/srcwget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gztar -zvxf m4-1.4.9.tar.gzcd m4-1.4.9/./configure && make && make installcd ../wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gztar -zvxf autoconf-2.62.tar.gz
cd autoconf-2.62/./configure && make && make install
5.這是再次執行sudo /usr/local/php/bin/phpize,就可以成功產生configure檔案了。(phpize是用來擴充php擴充模組的,通過phpize可以建立php的外掛模組,官方說明網址為:http://php.net/manual/en/install.pecl.phpize.php)
6.用sudo方式執行命令./configure --with-php-config=/usr/local/php/bin/php-config; make ; make install
7.編譯完成了,還需要做的是在/usr/local/lib/php.ini檔案中加入extension值:extension=memcache.so
8.重啟/usr/local/php/sbin/php-fpm程式使配置生效,但是報錯:
ERROR: failed to open configuration file ‘/usr/local/php/etc/php-fpm.conf‘: No such file or directory (2)
ERROR: failed to load configuration file ‘/usr/local/php/etc/php-fpm.conf‘
ERROR: FPM initialization failed
解決辦法為: (1)cd /usr/local/php/etc/; (2)mv php-fpm.conf.default php-fpm.conf
9.重啟仍然出現問題:ERROR: [pool www] cannot get uid for user ‘www‘。解決辦法為:編輯檔案vim /usr/local/php/etc/php-fpm.conf,
把user = nobody group = nobody 中的nobody修改成有效使用者和使用者組名稱。
10.php擴充可使用的一些方法可參考網址:http://blog.csdn.net/fwkjdaghappy1/article/details/7592337
參考網址:
http://www.dewen.org/q/844
http://hi.baidu.com/thinkinginlamp/item/5a3b2531e25dc6f62784f4fb
http://code.google.com/p/memcached/wiki/PHPClientComparison
https://bugs.launchpad.net/keystone/+bug/843080
http://www.cppblog.com/kefeng/archive/2010/10/11/129422.html
https://bugs.launchpad.net/libmemcached/+bug/656010
http://blog.csdn.net/vaal_water/article/details/6439483
http://www.spiration.co.uk/post/1385/Cannot-find-autoconf.-Please-check-your-autoconf-installation
https://gist.github.com/3359828
http://www.2cto.com/kf/201111/110140.html
http://blog.johntechinfo.com/technology/264
http://www.oschina.net/question/231397_36921
http://www.cnblogs.com/huangjingzhou/articles/2093706.html
http://blog.csdn.net/fwkjdaghappy1/article/details/7592337
[轉]編譯安裝libevent,memcache,以及php的memcached擴充