linux下给php安装memcached及memcache扩展(转)

http://kimi.it/257.html (另外的方法)
linux安装memcached及memcache扩展
1、安装libevent函数库
下载地址:http://libevent.org
默认被安装到:/usr/local/lib目录下
安装memcached以前须要先安装libevent函数库。
能够经过#ls -al /usr/local/lib | grep libevent命令查看是否已安装libevent函数库。
若是没安装,则需下载并安装libevent函数库。
 
2、安装memcached
下载地址:http://memcached.org
默认被安装到:/usr/local/bin目录下
安装完毕后,
先将libevent包路径加入/etc/ld.so.conf文件中
#vi /etc/ld.so.conf
在最后面一行加入/usr/local/lib
 
完成后输入如下命令启动memcached主程序
/usr/local/bin/memcached -d -m 1024  -u root -l 须要访问memcached的客户端ip地址 -p 11211 -c 1024 -P /tmp/memcached.pid
经常使用启动参数以下:
-m:最大使用内存,以MB为单位,默认64。
-p:进程所使用的TCP进程端口,默认11211。
-d:将memcached做为后台守护进程运行。
-u:启动用户。
-P:进程文件存放路径。
-c:最大运行并发数,默认1024。
-l:监听服务地址(即容许telnte登陆的IP)。
 
若是出现如下报错:error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
则说明memcached找不到libevent的位置,解决办法及缘由以下:
缘由之一:虽然刚刚咱们在/etc/ls.so.conf文件里添加了libevent包目录,但系统尚未识别到这个新的动态连接库。
解决办法:咱们须要执行一下ldconfig命令,这个命令一般在系统启动时运行,而当用户安装了一个新的动态连接库时,就须要手工运行这个命令。
这个命令的用途:默认搜寻/lilb和/usr/lib,以及配置文件/etc/ld.so.conf内所列的目录下的库文件。
 
启动完成后,可查看memcached主程序是否存在
#pstree | grep mem
 
3、安装memcache扩展
下载地址:http://pecl.php.net/package/memcache
memcache是php的一个扩展模块,安装前应先保证目前具有php环境。
先找到phpize的存在目录(若是是经过yum安装的php,则存在于/usr/bin中,若是没找到它们,则#yum install php-devel并重启)
解压memcache压缩包后,“进入解压出的文件夹中”。接下来使用phpzie将memcache编译到php扩展模块中。
#/usr/bin/phpize
#./configure --with-php-config=/usr/bin/php-config
(此时若是error: memcache support requires ZLIB报错,则说明没有zlib,能够yum一个,以后重启:#yum install -y zlib.x86_64 zlib-devel.x86_64)
检测成功后就能够用make编译memcache了:
#make
#make install
Installing shared extensions:     /usr/lib64/php/modules/
(上面的结果表示:扩展将被安装到/usr/lib64/php/modules/目录)
最后还须要修改php.ini配置项,过程以下:
#vim /etc/php.ini
(在700多行找到下面的命令,将注释去掉,有些没有也可手动添加)
extension_dir = "/usr/lib64/php/modules/"(地址是上面make时显示的地址)
extension = "memcache.so"
extension = "pdo_mysql.so"
重启服务器
 
能够用#telnet memcached所在服务器ip地址 11211
来查看是否能够链接memcached
 
以后能够经过phpinfo函数查看memcache的配置信息php

相关文章
相关标签/搜索