memcached 之前安装过一次,后来一次断电,虚拟机挂的那个彻底,之前装的那次只是很简单的记录了一下,最近有个好玩的小东西用到了memcache,没办法重新装memcache 遇到一堆一堆的坑,记录下,也供大家参考~
环境 :centeos 6.5 php7.0.2 memcached 1.5.1 扩展 memcached3.0.0
https://pecl.php.net/package/memcached
可以查看memcached 对应版本所需 libevent包版本
查看libevent包版本
rpm -qa|grep libevent 我的提示没有这个包,如果版本不够则卸载重新安装
卸载:rpm -e libevent-1.4.13-4.el6.x86_64
重新安装 libevent
tar -zxvf libevent-2.0.21-stable.tar.gz
安装
./configure --prefix=/usr/local/libevent (指定安装到/usr/local/libevent目录下)
编译:make
make install
下载最新版memcached
wget http
:
//memcached.org/latest
解压 tar -zxvf latest
当前目录 pwd /usb/src/
进入目录 cd memcached-1.5.1/ (这个目录在安装php扩展的时候需要用到 memcahced.h 这个文件)
解压 tar
-
zxvf memcached
-
1.x
.
x
.
tar
.
gz
生成配置文件 ./configure --with-libevent=/usr/local/libevent/ --prefix=/usr/local/memcached
我之后才装的libevent,报了这个错,解决办法参照上面libevent安装
报这个错:需要安装 libevent
checking for libevent directory... configure: error: libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
If it's already installed, specify its path using --with-libevent=/dir/
最后
checking for xsltproc... /usr/bin/xsltproc
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands
make && make install
最后
make[3]: Entering directory `/usb/src/memcached-1.5.1'
/bin/mkdir -p '/usr/local/memcached/bin'
/usr/bin/install -c memcached '/usr/local/memcached/bin'
/bin/mkdir -p '/usr/local/memcached/include/memcached'
/usr/bin/install -c -m 644 protocol_binary.h '/usr/local/memcached/include/memcached'
make[3]: Leaving directory `/usb/src/memcached-1.5.1'
make[2]: Leaving directory `/usb/src/memcached-1.5.1'
make[1]: Leaving directory `/usb/src/memcached-1.5.1'
安装成功
启动memcached
/usr/local/memcached/bin/memcached -d -m 128 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
ps -ef|grep memcached
root 787 0.0 0.0 0 0 ? S 20:07 0:00 [vmmemctl]
root 21079 0.0 0.1 442284 3660 ? Ssl 21:17 0:00 /usr/local/memcached/bin/memcached -d -m 128 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
root 21761 0.0 0.0 103328 860 pts/1 S+ 21:30 0:00 grep mem
安装PHP-memcached
git clone https://github.com/php-memcached-dev/php-memcached.git
cd php-memcached/
git checkout php7
执行 /usr/local/php7/bin/phpize
执行 ./configure
报错:
checking for memcached msgpack support... disabled
checking for libmemcached location... configure: error: Unable to find memcached.h under /usb/src/memcached-1.5.1/
这里卡了好久...
百度:
执行:
sudo mkdir -p /usr/lib/x86_64-linux-gnu/include/libmemcached
sudo ln -s/usb/src/memcached-1.5.1
/memcached
.
h /usr/lib/x86_64-linux-gnu/include/libmemcached/memcached
.
h
然后重新执行
./configure --with-php-config=/usr/local/php7/bin/php-config --enable-memcached --with-libmemcached-dir=/usr/lib/x86_64-linux-gnu --disable-memcached-sasl
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
make && make install
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
cd /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012
此时发现 多了第一个 memcached.so 的扩展
重启php。
service php-fpm restart
在php.ini 中加入 memcache扩展
extension=memcached.so;
测试文件中 phpini(); 查找 memcached
memcached
memcached support | enabled |
Version | 3.0.0b1 |
libmemcached version | 1.0.18 |
SASL support | no |
Session support | yes |
igbinary support | no |
json support | no |
msgpack support | no |
搞定~!
附: php 7各个安装包
点击打开链接