安装memcached

由于前文“Centos 7.2 yum安装php7”中升级了php到php7,导致之前可以正常使用的phpmyadmin、memcache等无法继续使用,需要重新编译安装,memcache目前未找到有效的解决方法,只好重新安装memcached来替代之前的memcache。此处介绍memcached的安装编译。

1、试图按以前的经验,直接升级memcache:

[root@iZ23d ~]# pecl upgrade memcache

bash: pecl: command not found...

根据这边的提示

,需要安装相应的

yum install php-devel php-pear httpd-devel

[root@iZ23d ~]# yum install php70w-devel php70w-pear php70w-httpd-devel

Loaded plugins: langpacks

Repository base is listed more than once in the configuration

Repository updates is listed more than once in the configuration

。。。。 【其中省略】

Warning: RPMDB altered outside of yum.

Installing : php70w-process-7.0.0-1.w7.x86_64 1/4

Installing : php70w-xml-7.0.0-1.w7.x86_64 2/4

Installing : 1:php70w-pear-1.10.1-1.w7.noarch 3/4

Installing : php70w-devel-7.0.0-1.w7.x86_64 4/4

Verifying : php70w-devel-7.0.0-1.w7.x86_64 1/4

Verifying : php70w-xml-7.0.0-1.w7.x86_64 2/4

Verifying : 1:php70w-pear-1.10.1-1.w7.noarch 3/4

Verifying : php70w-process-7.0.0-1.w7.x86_64 4/4

Installed:

php70w-devel.x86_64 0:7.0.0-1.w7 php70w-pear.noarch 1:1.10.1-1.w7

Dependency Installed:

php70w-process.x86_64 0:7.0.0-1.w7 php70w-xml.x86_64 0:7.0.0-1.w7

Complete!

继续按偷懒的方法升级:

[root@iZ23d ~]# pecl upgrade memcache

downloading memcache-2.2.7.tgz ...

Starting to download memcache-2.2.7.tgz (36,459 bytes)

.....done: 36,459 bytes

11 source files, building

running: phpize

Configuring for:

PHP Api Version: 20151012

Zend Module Api No: 20151012

Zend Extension Api No: 320151012

。。。 【其中省略】

config.status: executing libtool commands

running: make

/bin/sh /var/tmp/pear-build-rootEb5cjP/memcache-2.2.7/libtool --mode=compile cc -I/usr/include/php -I. -I/var/tmp/memcache -DPHP_ATOM_INC -I/var/tmp/pear-build-rootEb5cjP/memcache-2.2.7/include -I/var/tmp/pear-build-rootEb5cjP/memcache-2.2.7/main -I/var/tmp/memcache -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /var/tmp/memcache/memcache.c -o memcache.lo

libtool: compile: cc -I/usr/include/php -I. -I/var/tmp/memcache -DPHP_ATOM_INC -I/var/tmp/pear-build-rootEb5cjP/memcache-2.2.7/include -I/var/tmp/pear-build-rootEb5cjP/memcache-2.2.7/main -I/var/tmp/memcache -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /var/tmp/memcache/memcache.c -fPIC -DPIC -o .libs/memcache.o

/var/tmp/memcache/memcache.c:40:40: fatal error: ext/standard/php_smart_str.h: No such file or directory

include "ext/standard/php_smart_str.h"

                                    ^

compilation terminated.

make: *** [memcache.lo] Error 1

ERROR:

`make' failed

说明升级失败,缺乏

php_smart_str.h

文件,查看是否有相应文件的源文件:

[root@iZ23d ~]# find / -name php_smart_str.h

/root/php-5.4.16/ext/standard/php_smart_str.h

以上说明 php5中有相应的文件,但是已经下载并解压的 php7源安装包中却没有相应文件,而

这边前人的经验

也表面,可能是Php7本身的某些扩展未做到位。

而根据这边的说法之前版本的php中的 php_smart_str.h 在 php7 中已经改名为 php_smart_string.h

查看相应的文件:

[root@iZ23d ~]#

find / -name php_smart_string.h

/usr/include/php-zts/php/ext/standard/php_smart_string.h

/usr/include/php/ext/standard/php_smart_string.h

/root/php-7.0.1RC1/ext/standard/php_smart_string.h

的确有相应的文件,但是,尝试把相应的文件拷贝一份并命名为相应的 php_smart_str.h 后,重新升级编译安装,并不能解决问题。

在github和stackoverflow均看到此问题暂时没有解决方案,只能等Php7完善。不得已,只能放弃。

在寻找memcache解决方案的过程中,发现memcached碰到的问题几乎和memcache一样,但是,却从 stackoverflow 找到一个可行的 memcached 安装方法,并证实有效。下面是具体的过程。

第一步,直接git clone:

[root@iZ23d ~]# **git clone

https://gith<wbr>ub.com/php-m<wbr>emcached-dev<wbr>/php-memcach<wbr>ed**

Cloning into 'php-memcached'...

remote: Counting objects: 2965, done.

remote: Total 2965 (delta 0), reused 0 (delta 0), pack-reused 2965

Receiving objects: 100% (2965/2965), 931.47 KiB | 8.00 KiB/s, done.

Resolving deltas: 100% (1774/1774), done.

第二步:

[root@iZ23d ~]# cd php-memcached

[root@iZ23d php-memcached]# git checkout php7

Branch php7 set up to track remote branch php7 from origin.

Switched to a new branch 'php7'

第三步:

[root@iZ23d php-memcached]# phpize

Configuring for:

PHP Api Version: 20151012

Zend Module Api No: 20151012

Zend Extension Api No: 320151012

第四步:

configure

[root@iZ23d php-memcached]#

./configure

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

。。。 【省略部分】

checking for memcached session support... enabled

checking for memcached igbinary support... disabled

checking for memcached msgpack support... disabled

checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located

第五步:根据错误提示,重新

configure

先找到相应文件:

[root@iZ23d php-memcached]#find / -name libmemcached

/usr/local/libmemcached

/usr/local/libmemcached/include/libmemcached

/root/libmemcached-1.0.18/libmemcached

根据文件位置,增加参数

configure

[root@iZ23d php-memcached]# ./configure --with-libmemcached-dir=/usr/local/libmemcached

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

checking for a sed that does not truncate output... /usr/bin/sed

checking for cc... cc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

。。。

checking for sasl/sasl.h... yes

checking whether libmemcached supports sasl... no

configure: error: no, libmemcached sasl support is not enabled. Run configure with --disable-memcached-sasl to disable this check

再根据新提示,继续:

[root@iZ23d php-memcached]# **./configure

--with-libmemcached-dir

=/usr/local/libmemcached

--disable

-memcached-sasl**

checking for grep that handles long lines and -e... /usr/bin/grep

。。。

configure: creating ./config.status

config.status: creating config.h

config.status: executing libtool commands

终于未出现错误提示!

第六步,make:

[root@iZ23d php-memcached]# make

/bin/sh /root/php-memcached/libtool --mode=compile cc -I/usr/include/php -I. -I/root/php-memcached -DPHP_ATOM_INC -I/root/php-memcached/include -I/root/php-memcached/main -I/root/php-memcached -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/libmemcached/include -DHAVE_CONFIG_H -g -O2 -c /root/php-memcached/php_memcached.c -o php_memcached.lo

libtool: compile: cc -I/usr/include/php -I. -I/root/php-memcached -DPHP_ATOM_INC -I/root/php-memcached/include -I/root/php-memcached/main -I/root/php-memcached -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/libmemcached/include -DHAVE_CONFIG_H -g -O2 -c /root/php-memcached/php_memcached.c -fPIC -DPIC -o .libs/php_memcached.o

。。。。。 【省略部分】

libtool: install: cp ./.libs/memcached.so /root/php-memcached/modules/memcached.so

libtool: install: cp ./.libs/memcached.lai /root/php-memcached/modules/memcached.la

libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_45:/root/bin:/sbin" ldconfig -n /root/php-memcached/modules


Libraries have been installed in:

/root/php-memcached/modules

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

  • add LIBDIR to the `LD_LIBRARY_PATH' environment variable

    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'.

根据提示,继续

make test

[root@iZ23d php-memcached]# make test

Build complete.

Don't forget to run 'make test'.

。。。【省略部分】

Thank you for helping to make PHP better.

第七部,

make install

[root@iZ23d php-memcached]# make install

Installing shared extensions: /usr/lib64/php/modules/

第八步,

重启 Apache,在/etc/php.ini

的最后添加 extension="memcached.so",保存退出,重启Apache

[root@iZ23d php-memcached]#

cd ..

[root@iZ23d ~]#

systemctl restart httpd.service

第九步,验证检查 memcached 安装结果:

查看 php 版本,看看会否报错,若报错,说明 memcached 安装错误,否则多半表示安装成功:

[root@iZ23d ~]# **php -v **

PHP

7.0.0 (cli)(built: Dec 2 2015 20:42:32) ( NTS )

Copyright (c) 1997-2015 The PHP Group

Zend Engine

v3.0.0, Copyright (c) 1998-2015 Zend Technologies

以上结果说明,memcached安装成功。

查看phpinfo,已经显示memcached的扩展内容,内容展示如下:

<a target="_blank" name="module_memcached" style="text-decoration: none; color: rgb(42, 88, 111); outline: none;">memcached</a>

| memcached support | enabled |
| Version | 2.2.0 |
| libmemcached version | 1.0.18 |
| SASL support | no |
| Session support | yes |
| igbinary support | no |
| json support | no |
| msgpack support | no |

| Directive | Local Value | Master Value |
| memcached.compression_factor | 1.3 | 1.3 |
| memcached.compression_threshold | 2000 | 2000 |
| memcached.compression_type | fastlz | fastlz |
| memcached.serializer | php | php |
| memcached.sess_binary | 0 | 0 |
| memcached.sess_connect_timeout | 1000 | 1000 |
| memcached.sess_consistent_hash | 0 | 0 |
| memcached.sess_lock_expire | 0 | 0 |
| memcached.sess_lock_max_wait | 0 | 0 |
| memcached.sess_lock_wait | 150000 | 150000 |
| memcached.sess_locking | 1 | 1 |
| memcached.sess_number_of_replicas | 0 | 0 |
| memcached.sess_prefix | memc.sess.key. | memc.sess.key. |
| memcached.sess_randomize_replica_read | 0 | 0 |
| memcached.sess_remove_failed | 0 | 0 |
| memcached.store_retry_count | 2 | 2 |

再次证明 memcached 安装成功!

第十步,启动 memcached :

[root@iZ23d ~]# systemctl start memcached.service

查看状态:

[root@iZ23d ~]# systemctl status memcached.service

● memcached.service - Memcached

Loaded: loaded (/usr/lib/systemd/system/memcached.service; disabled; vendor preset: disabled)

Active: active (running) since Mon 2015-12-21 19:55:07 CST; 14s ago

Main PID: 1426 (memcached)

CGroup: /system.slice/memcached.service

       └─1426 /usr/bin/memcached -u memcached -p 11211 -m 64 -c 1024

Dec 21 19:55:07 iZ23d2e6hoqZ systemd[1]: Started Memcached.

Dec 21 19:55:07 iZ23d2e6hoqZ systemd[1]: Starting Memcached...

设置开机启动:

[root@iZ23d ~]# systemctl enable memcached.service

Created symlink from /etc/systemd/system/multi-user.target.wants/memcached.service to /usr/lib/systemd/system/memcached.service.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,222评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,455评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,720评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,568评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,696评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,879评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,028评论 3 409
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,773评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,220评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,550评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,697评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,360评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,002评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,782评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,010评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,433评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,587评论 2 350

推荐阅读更多精彩内容