红联Linux门户
Linux帮助

Linux基于libmemcached,php扩展memcached的安装

发布时间:2016-09-19 16:14:43来源:linux网站作者:暝冥佷愛伱
安装环境:CentOS 6.4
php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached。
 
一、下载软件
1、libmemcached下载地址:https://launchpad.net/libmemcached/+download
文件:memcached-2.2.0.tgz
2、php-memcached下载地址:http://pecl.php.net/package/memcached
文件:libmemcached-1.0.18.tar.gz 
 
二、安装libmemcached (libmemcached-1.0.18.tar.gz)
[root@localhost mysoft]#mkdir /usr/local/libmemcached
[root@localhost mysoft]# tar -zxvf libmemcached-1.0.18.tar.gz
[root@localhost mysoft]# cd libmemcached-1.0.18
[root@localhost mysoft]# ./configure --prefix=/usr/local/libmemcached/ --with-memcached
[root@localhost mysoft]# make
[root@localhost mysoft]# make install
 
三、安装php-memcached(php-memcached-2.2.0.tgz)
[root@localhost mysoft]# mkdir /usr/local/phpmemcached
[root@localhost mysoft]# tar -zxvf php-memcached-2.2.0.tgz
[root@localhost mysoft]# cd memcached-2.2.0/
[root@localhost mysoft]# /phpstudy/server/php/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@localhost mysoft]# ./configure --enable-memcached --with-php-config=/phpstudy/server/php/bin/php-config  --with-libmemcached-dir=/usr/local/libmemcached/ --disable-memcached-sasl
[root@localhost mysoft]# make
[root@localhost mysoft]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
[root@localhost mysoft]# ll /phpstudy/server/php/lib/php/extensions/no-debug-non-zts-20121212/
总用量 852
-rwxr-xr-x  1 root root 333097 9月  18 08:24 memcached.so
-rwxr-xr-x. 1 root root 533480 9月   2 23:50 opcache.so
[root@localhost mysoft]# vi /phpstudy/server/php/etc/php.ini 
加上:extension=memcached.so
[root@localhost mysoft]# phpstudy restart
Linux基于libmemcached,php扩展memcached的安装
 
四、安装遇到的问题
1、安装libmemcached过程中不要忘了,--with-memcached,不然会提示你
checking for memcached... no
configure: error: "could not find memcached binary"
2、你的memcached是不是1.2.4以上的,如果不是会提示你
clients/ms_thread.o: In function `ms_setup_thread':
/home/zhangy/libmemcached-0.42/clients/ms_thread.c:225: undefined reference to `__sync_fetch_and_add_4'
clients/ms_thread.o:/home/zhangy/libmemcached-0.42/clients/ms_thread.c:196: more undefined references to `__sync_fetch_and_add_4' follow
collect2: ld returned 1 exit status
make[2]: *** [clients/memslap] Error 1
make[2]: Leaving directory `/home/zhangy/libmemcached-0.42'
解决办法是--disable-64bit CFLAGS="-O3 -march=i686",如果不用这个64位的long型数据,我想php扩展memcached,memcache也就没什么区别了,装memcached也就没什么意思了。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/24305.html