分类: 系统运维
2012-09-11 20:23:50
php的memcache扩展安装分为两个步骤
第一个步骤是:memcache缓存服务器的安装
第二个步骤是:php的memcached模块的安装
下面详细介绍各个部分的安装过程
memcached缓存服务器的安装
一、memcached 的编译安装
准备:
Memcached下载地址:
libevent下载地址:
安装步骤:
1. 下载libevent & memcached 源码包
libevent-1.3.tar.gz
memcached-1.2.2.tar.gz
2. 解压缩 libevent-1.3.tar.gz ,编译安装
# tar zxvf libevent-1.3.tar.gz
# cd libevent-1.3
# ./configure --prefix=/usr/local/libevent
# make ; make install
测试libevent是否安装成功:
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3
-rw-r–r– 1 root root 454156 11?? 12 17:38 libevent.a
-rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
3. 解压缩 memcached-1.2.2.tar.gz, 编译安装
# tar zxvf memcached-1.2.2.tar.gz
# cd memcached-1.2.2
# ./configure --prefix=/usr/local/memchached --with-libevent=/usr/local/libevent
# make;make install
测试是否成功安装memcached:
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug
4. 作软连接,否则运行memcached的时候将找不到libevent模块
# ln -s /usr/local/libevent/lib/libevent-1.3.so.1 /usr/lib
5.启动memcached
# /usr/local/memcached/bin/memcached -d -m 256 -p 11211 -u root
OK !!! 搞定! ^^
二、php的memcached模块
# tar vxzf memcache-1.5.tgz
# cd memcache-1.5
# /usr/local/php/bin/phpize
# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
# make
# make install
安装完后会有类似这样的提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/
把这个记住,然后修改php.ini,把
extension_dir = "./"
修改为
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
并添加一行
extension=memcache.so
3、测试脚本
自己写一个PHP程序测试一下吧
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;
?>