Centos 7.2 及php7环境下升级memcache未果,改安装 memcached

Centos 7.2 及php7环境下升级memcache未果,改安装 memcached

分类: 运维  |  标签: php php7,memcached,centos  |  作者: xahuo 相关  |  发布日期 : 2015-12-23  |  热度 : 553°
 
 

由于前文“http://www.aiuxian.com/article/p-3220064.html”中升级了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 链接地址   
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的扩展内容,内容展示如下:
 


 

memcached

memcached supportenabled
Version 2.2.0
libmemcached version 1.0.18
SASL support no
Session support yes
igbinary support no
json support no
msgpack support no
DirectiveLocal ValueMaster 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.
posted @ 2016-04-01 01:04  爱博子  阅读(1521)  评论(0编辑  收藏  举报