运维日常:五分钟搞定PHP的redis问题

一、前言

1.需求

2.解决
LNMP环境中的PHP缺少redis扩展包,导致访问页面报错500,处理问题,安装PHP扩展功能redis。

下面记录整个过程,如果不想看,而只想在最短的时间内搞定这个问题,请直接翻到最后,使用脚本。

二、安装

1.下载扩展包

[[email protected] source]# git clone https://github.com/nicolasff/phpredis
Cloning into ‘phpredis‘...
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 9450 (delta 11), reused 15 (delta 7), pack-reused 9421
Receiving objects: 100% (9450/9450), 5.40 MiB | 2.10 MiB/s, done.
Resolving deltas: 100% (6483/6483), done.

2.phpize检测安装

[[email protected] source]# cd phpredis/
[[email protected] phpredis]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012

3.预编译

[[email protected] phpredis]# ./configure --with-php-config=/usr/local/php/bin/php-config
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 suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable redis support... yes, shared
checking whether to enable sessions... yes
checking whether to enable igbinary serializer support... no
checking whether to enable lzf compression... no
checking use system liblzf... no
checking for redis igbinary support... disabled
checking for git... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

4.编译安装

[[email protected] phpredis]# make && make install
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/redis.c -o redis.lo
mkdir .libs
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/redis.c  -fPIC -DPIC -o .libs/redis.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/redis_commands.c -o redis_commands.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/redis_commands.c  -fPIC -DPIC -o .libs/redis_commands.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/library.c -o library.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/library.c  -fPIC -DPIC -o .libs/library.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/redis_session.c -o redis_session.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/redis_session.c  -fPIC -DPIC -o .libs/redis_session.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/redis_array.c -o redis_array.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/redis_array.c  -fPIC -DPIC -o .libs/redis_array.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/redis_array_impl.c -o redis_array_impl.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/redis_array_impl.c  -fPIC -DPIC -o .libs/redis_array_impl.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/redis_cluster.c -o redis_cluster.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/redis_cluster.c  -fPIC -DPIC -o .libs/redis_cluster.o
/bin/sh /server/source/phpredis/libtool --mode=compile cc  -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /server/source/phpredis/cluster_library.c -o cluster_library.lo
cc -I. -I/server/source/phpredis -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /server/source/phpredis/cluster_library.c  -fPIC -DPIC -o .libs/cluster_library.o
/bin/sh /server/source/phpredis/libtool --mode=link cc -DPHP_ATOM_INC -I/server/source/phpredis/include -I/server/source/phpredis/main -I/server/source/phpredis -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o redis.la -export-dynamic -avoid-version -prefer-pic -module -rpath /server/source/phpredis/modules  redis.lo redis_commands.lo library.lo redis_session.lo redis_array.lo redis_array_impl.lo redis_cluster.lo cluster_library.lo
cc -shared  .libs/redis.o .libs/redis_commands.o .libs/library.o .libs/redis_session.o .libs/redis_array.o .libs/redis_array_impl.o .libs/redis_cluster.o .libs/cluster_library.o   -Wl,-soname -Wl,redis.so -o .libs/redis.so
creating redis.la
(cd .libs && rm -f redis.la && ln -s ../redis.la redis.la)
/bin/sh /server/source/phpredis/libtool --mode=install cp ./redis.la /server/source/phpredis/modules
cp ./.libs/redis.so /server/source/phpredis/modules/redis.so
cp ./.libs/redis.lai /server/source/phpredis/modules/redis.la
PATH="$PATH:/sbin" ldconfig -n /server/source/phpredis/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /server/source/phpredis/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‘.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
```~~

**5.修改php.ini文件**
[[email protected] phpredis]# vim /usr/local/php/etc/php.ini
[[email protected] phpredis]# tail -n 1 /usr/local/php/etc/php.ini
extension="redis.so"

**6.重启LNMP环境**
[[email protected] phpredis]# lnmp restart
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Stoping LNMP...
Stoping nginx...  done
Shutting down MySQL. SUCCESS!
Gracefully shutting down php-fpm . done
Starting LNMP...
Starting nginx...  done
Starting MySQL. SUCCESS!
Starting php-fpm  done

**7.检测是否安装成功redis扩展**
[[email protected] phpredis]# php -m |grep redis
redis

**一键安装**
#!/bin/bash
## 2018-10-15 write by leo;

redis=`php -m |grep redis`

yum install -y wget vim git
mkdir -pv  /server/{source,web,data}
cd /server/source
git clone https://github.com/nicolasff/phpredis
cd phpredis/  && /bin/bash /usr/local/php/bin/phpize
/server/source/phpredis/configure --with-php-config=/usr/local/php/bin/php-config
if [ $? -eq 0 ];then
    make && make install
else
    echo "configure error!!!"
fi
echo "extension=‘redis.so‘" >> /usr/local/php/etc/php.ini
lnmp restart
if [ $? -eq 0 ];then
        echo "lnmp restart finish!"
else
        echo "restart services error!!!"
fi
echo "$redis ext finish!!!"

原文地址:http://blog.51cto.com/leoheng/2300286

时间: 2024-10-08 16:43:43

运维日常:五分钟搞定PHP的redis问题的相关文章

zookeeper-非常重要的zab协议-《每日五分钟搞定大数据》

上篇文章paxos与一致性说到zab是在paxos的基础上做了重要的改造,解决了一系列的问题,这一篇我们就来说下这个zab. zab协议的全称是ZooKeeper Atomic Broadcast即zookeeper"原子""广播"协议.它规定了两种模式:崩溃恢复和消息广播 恢复模式 什么时候进入? 当整个服务框架在启动过程中 当Leader服务器出现网络中断崩溃退出与重启等异常情况 当有新的服务器加入到集群中且集群处于正常状态(广播模式),新服会与leader进行

HDFS-异常大全-《每日五分钟搞定大数据》

点击看<每日五分钟搞定大数据>完整思维导图以及所有文章目录 问题1:Decomminssioning退役datanode(即删除节点) 1.配置exclude: <name>dfs.hosts.exclude</name> <value>/data/hadoop/excludes</value> 在/data/hadoop/excludes文件添加要退役的节点ip(可同时退役多个,一个一行) 2.配置完后刷新节点 # $HADOOP_HOME/b

一篇文章搞懂DataSet、DataFrame、RDD-《每日五分钟搞定大数据》

1. 三者共性: 1.RDD.DataFrame.Dataset全都是spark平台下的分布式弹性数据集,为处理超大型数据提供便利 2.三者都有惰性机制,执行trainform操作时不会立即执行,遇到Action才会执行 3.三者都会根据spark的内存情况自动缓存运算,这样即使数据量很大,也不用担心会内存溢出 4.三者都有partition的概念,如 var predata=data.repartition(24).mapPartitions{       PartLine => {     

五分钟搞定 Linux 文档全部知识,就看这篇文章

写在前面 我们都知道Linux是一个支持多用户.多任务的系统,这也是它最优秀的特性,即可能同时有很多人都在系统上进行工作,所以千万不要强制关机,同时,为了保护每个人的隐私和工作环境,针对某一个文档(文件.目录),Linux系统定义了三种身份,分别是拥有者(owner).群组(group).其他人(others),每一种身份又对应三种权限,分别是可读(readable).可写(writable).可执行(excutable). 文档属性 使用命令ls -al --full-time,或者此命令的简

zookeeper-1.操作与应用场景-《每日五分钟搞定大数据》

Zookeeper作为一个分布式协调系统提供了一项基本服务:分布式锁服务,分布式锁是分布式协调技术实现的核心内容.像配置管理.任务分发.组服务.分布式消息队列.分布式通知/协调等,这些应用实际上都是基于这项基础服务由用户自己摸索出来的. 1.Zookeeper在大数据系统中的常见应用 zookeeper作为分布式协调系统在大数据领域非常常用,它是一个很好的中心化管理工具.下面举几个常见的应用场景. 1.1.HDFS/YARN HA(分布式锁的应用):Master挂掉之后迅速切换到slave节点.

redis- info调优入门-《每日五分钟搞定大数据》

本文根据redis的info命令查看redis的内存使用情况以及state状态,来观察redis的运行情况以及需要作出的相应优化. info 1.memory used_memory:13409011624 #used_memory=实际缓存占用的内存+Redis自身运行所占用的内存(如元数据.lua).                        #这个值是由Redis使用内存分配器分配的内存,不包括内存碎片浪费的内存. used_memory_rss:13740019719 #从操作系统上

YARN-异常大全-《每日五分钟搞定大数据》

#问题描述:NodeManager1 cpu负载飙高,进程还在但是不再向ResourceManager发送心跳,不断重复下文2的动作.心跳停止一段时间后会重连上RM但是cpu仍然很高,再过一段时间心跳再停,一直循环. #节点管理器的日志解析1.localizing:容器开始从HDFS下载资源,HDFS文件的状态从INIT变成下载. 2018年8月25日16:15:38592信息org.apache.hadoop .yarn.server.nodemanager.containermanager.

redis- 使用info轻松调优-《每日五分钟搞定大数据》

本文根据redis的info命令查看redis的内存使用情况以及state状态,来观察redis的运行情况以及需要作出的相应优化. info 1.memory used_memory:13409011624 #used_memory=实际缓存占用的内存+Redis自身运行所占用的内存(如元数据.lua).                        #这个值是由Redis使用内存分配器分配的内存,不包括内存碎片浪费的内存. used_memory_rss:13740019719 #从操作系统上

01. SpringCloud实战项目-五分钟搞懂分布式基础概念

SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. PassJava 是一款Java面试刷题的开源系统,可以用零碎时间利用小程序查看常见面试题,夯实Java基础. PassJava 项目可以教会你如何搭建SpringBoot项目,Spring Cloud项目 采用流行的技术,如 SpringBoot.MyBatis.Redis. MySql. Mon