日常运维(五分钟实现安装PHP的redis扩展)

【日常运维(五分钟实现安装PHP的redis扩展)】学向勤中得,萤窗万卷书。这篇文章主要讲述日常运维:五分钟实现安装PHP的redis扩展相关的知识,希望能为你提供帮助。
1、下载扩展包

[root@lp 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检测安装
[root@lp source]# cd phpredis/ [root@lp phpredis]# /usr/local/php/bin/phpize Configuring for: PHP Api Version:20151012 Zend Module Api No:20151012 Zend Extension Api No:320151012

3、预编译
[root@lp 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... nocreating libtool appending configuration tag "CXX" to libtool configure: creating ./config.status config.status: creating config.h

4、编译安装
[root@lp 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/modulesredis.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/modulesIf 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.confSee any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. --------------------------------------------------------------------Build complete. Dont forget to run make test.Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/

5、修改php.ini文件
[root@lp phpredis]# vim /usr/local/php/etc/php.ini [root@lp phpredis]# tail -n 1 /usr/local/php/etc/php.ini extension="redis.so"

6、重启LNMP环境
[root@lp 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-fpmdone

7.检测是否安装成功redis扩展
[root@lp phpredis]# php -m |grep redis redis

8、一键安装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!!!"


    推荐阅读