> Ubuntu >

ubuntu 12.04 apt-get安装配置阿里云OCS的php支持

之前介绍了centos/redhat下如何配置ocs的PHP环境支持,ubuntu下阿里云官方暂未提供相关帮助文档,ubuntu下模块名称不尽相同,所以本文介绍一下ubuntu12.04下如何配置环境来支持ocs服务,主要是sasl的配置
以下操作均为阿里云服务器操作实录

 

首先,还是先配置一下高大上的阿里云镜像源

1 vim /etc/apt/source.list

在最前面添加一下内容

01 deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
02 deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
03 deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
04 deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
05 deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
06 deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
07 deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
08 deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
09 deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
10 deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
11  
12 apt-get update //更新一下列表

然后通过ape-get配置GCC,G++

1 apt-get build-dep gcc
2 apt-get install build-essential

然后安装一下php5,php5-dev

1 apt-get install php5 php5-dev //同时会自动安装php5-cli和php5-common

安装配置sasl支持

1 apt-get install  libsasl2-dev cloog-ppl

安装指定版本的libmemcache

1 wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
2 tar -zxvf libmemcached-1.0.16.tar.gz
3 cd libmemcached-1.0.16/
4 ./configure --prefix=/usr/local/libmemcached
5 make;make install;make clean //这里会有点慢,可以去个洗手间之类的~

安装指定版本的memcached

1 cd..
2 wget http://pecl.php.net/get/memcached-2.1.0.tgz
3 tar zxvf memcached-2.1.0.tgz
4 cd memcached-2.1.0
5 phpize5
6 ./configure --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-sasl
7 make;make install;make clean

配置php支持memcache,然后测试

1 echo "extension=memcached.so" >>/etc/php5/conf.d/pdo.ini
2  
3 root@AY1212111202285f63122:/# php -m |grep mem
4 memcached

ok,配置完毕,开始测试

1 vim /var/www/ocs.php
01 < ?php
02 $connect new Memcached;
03 $connect->setOption(Memcached::OPT_COMPRESSION, false);
04 $connect->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
05 $connect->addServer('7d9cfd3014aa11e3.m.cnhzalicm10pub001.ocs.aliyuncs.com', 11211);
06 $connect->setSaslAuthData('7d9cfd3014aa11e3''******');
07 for($i=0;$i<10;$i++){ $connect->set("$i""world");
08 echo "key".$i."is:" ,$connect->get("$i")."
09 ";
10 }
11 $connect->quit();
12 ?>
01 php ocs.php
02 root@AY1212111202285f63122:/var/www# php ocs.php
03 key0is:world
04 key1is:world
05 key2is:world
06 key3is:world
07 key4is:world
08 key5is:world
09 key6is:world
10 key7is:world
11 key8is:world
12 key9is:world

配置完毕




(责任编辑:IT)