Memcached 安裝與配置php
最新的穩定版: wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
nginx
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gzvim
wget http://pecl.php.net/get/memcache-1.4.tgz (最好是根據相應的版原本選擇)ide
安裝libeventmemcached
tar zxvf libevent-1.4.14b-stable.tar.gzphp-fpm
cd libevent-1.4.14b-stablegoogle
./configure --prefix=/usr/local/libevent/spa
make.net
make installdebug
安裝memcached
tar zxvf memcached-1.4.5.tar.gz -C /usr/src
cd /usr/src/memcached-1.4.5
./configure --prefix=/usr/local/memcached/ --with-libevent=/usr/local/libevent
make && make install
運行memcached
/usr/local/memcached -d -m 128 -l localhost -p 11211 -u root
#說明:
# -d 設置 memcached 能夠使用的內存大小,單位爲 M ;
# -l 設置監聽的 IP 地址,若是是本機的話,一般能夠不設置此參數 ;
# -p 設置監聽的端口,默認爲 11211,因此也能夠不設置此參數;
# -u 指定用戶;
#若是遇到運行memcached時遇到問題,錯誤提示以下:
# /usr/local/servers/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
則運行 LD_DUBUG=libs 就能夠知道memcached啓動時庫的加載路徑。具體以下:
# LD_DEBUG=libs /usr/local/servers/memcached/bin/memcached -v
10929: find library=libevent-1.4.so.2 [0]; searching
10929: search cache=/etc/ld.so.cache
10929: search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib (system search path)
10929: trying file=/lib/tls/i686/sse2/libevent-1.4.so.2
10929: trying file=/lib/tls/i686/libevent-1.4.so.2
10929: trying file=/lib/tls/sse2/libevent-1.4.so.2
10929: trying file=/lib/tls/libevent-1.4.so.2
10929: trying file=/lib/i686/sse2/libevent-1.4.so.2
10929: trying file=/lib/i686/libevent-1.4.so.2
10929: trying file=/lib/sse2/libevent-1.4.so.2
10929: trying file=/lib/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/i686/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/tls/libevent-1.4.so.2
10929: trying file=/usr/lib/i686/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/i686/libevent-1.4.so.2
10929: trying file=/usr/lib/sse2/libevent-1.4.so.2
10929: trying file=/usr/lib/libevent-1.4.so.2
10929:
而後給libevent-1.4.so.2創建一個連接後再運行memcached:
# ln -s /usr/local/servers/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
安裝php的memcache擴展
能夠使用自帶的pecl安裝程序
#/usr/local/php/bin/pecl install memcache
#從源碼安裝
# tar zxvf memcache-1.4.tgz -C /usr/src
# cd /usr/src/memcached-1.4
# ./configure --prefix=/usr/local/memcache --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
# make && make install
#安裝完後會有相似這樣的提示:
#Installing shared extensions: /usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20060922/
#把這個記住,而後修改php.ini,
# vim /etc/php.ini
extension_dir = "./"
修改成
extension_dir = "/usr/local/php/lib/php/extensions/"
重啓php-fpm
/etc/rc.d/init.d/php-fpm restart
重啓nginx
/usr/local/nginx/sbin/nginx -s reload
php裏使用phpinfo()看到以下信息說明memcached擴展才算安裝好!