安装环境:centos7 + php 7.2.19
1. 下载地址:http://pecl.php.net/get/redis-5.0.2.tgz
wget -O /mydata/download/redis-5.0.2.tgz http://pecl.php.net/get/redis-5.0.2.tgz
2. 解压
tar zxf redis-5.0.2.tgz
3. 切换到已解压文件目录redis-5.0.2
cd redis-5.0.2 ls arrays.markdown cluster.markdown config.w32 CREDITS library.c README.markdown redis_array_impl.c redis_cluster.c redis_commands.h tests cluster_library.c common.h COPYING INSTALL.markdown library.h redis_array.c redis_array_impl.h redis_cluster.h redis_session.c cluster_library.h config.m4 crc16.h liblzf php_redis.h redis_array.h redis.c redis_commands.c redis_session.h
4. 阅读INSTALL.markdown,了解详细的安装步骤与说明
5. 开始安装
# phpize会根据本地的php环境生成configure文件 phpize Configuring for: PHP Api Version: 20170718 Zend Module Api No: 20170718 Zend Extension Api No: 320170718 # 查看configure帮助信息,了解详细的安装参数 ./configure --help `configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/bin', `/usr/local/lib' etc. You can specify an installation prefix other than `/usr/local' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] --target=TARGET configure for building compilers for TARGET [HOST] Optional Features and Packages: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-libdir=NAME Look for libraries in .../NAME rather than .../lib --with-php-config=PATH Path to php-config php-config --enable-redis Enable redis support --disable-redis-session Disable session support --disable-redis-json Disable json serializer support --enable-redis-igbinary Enable igbinary serializer support --enable-redis-msgpack Enable msgpack serializer support --enable-redis-lzf Enable lzf compression support --with-liblzf=DIR Use system liblzf --enable-shared=PKGS Build shared libraries default=yes --enable-static=PKGS Build static libraries default=yes --enable-fast-install=PKGS Optimize for fast installation default=yes --with-gnu-ld Assume the C compiler uses GNU ld default=no --disable-libtool-lock Avoid locking (might break parallel builds) --with-pic Try to use only PIC/non-PIC objects default=use both --with-tags=TAGS Include additional configurations automatic Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. # 设置配置参数 ./configure \ --with-php-config=/usr/local/php7.2/bin/php-config \ --enable-redis # 编译与安装 make && make install # 出现下面的信息(部分),说明安装成功 ... ... ... ... ---------------------------------------------------------------------- Libraries have been installed in: /mydata/download/redis-5.0.2/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/php7.2/lib/php/extensions/debug-non-zts-20170718/
6. 配置php.ini,添加extension=redis.so
; Redis extension
extension=redis.so
7. 重启php-fpm
service php-fpm restart Redirecting to /bin/systemctl restart php-fpm.service # php-fpm.service文件位置 /usr/lib/systemd/system/php-fpm.service # php-fpm.service文件内容 [Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/usr/local/php7.2/var/run/php-fpm.pid ExecStart=/usr/local/php7.2/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7.2/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
8. 检测redis扩展是否安装成功
# 查看php中已安装模块,显示redis,说明安装成功 php -m|grep redis redis
9. 关于扩展的使用说明,可以查看:https://github.com/phpredis/phpredis/#classes-and-methods