•  
  •  
  •  
  •  
  •  

上一篇文章已經為系統安裝好 Redis , 因為之後是要透過php來操作 Redis 所以要為php安裝 Redis 擴展。

先查詢 redis 版本
指令:sudo redis-cli -v
redis-cli 4.0.9

到官網下載相對應的擴展套件
http://pecl.php.net/package/redis

指令: wget http://pecl.php.net/get/redis-4.0.2.tgz
–2019-11-08 15:29:27– http://pecl.php.net/get/redis-4.0.2.tgz
Resolving pecl.php.net (pecl.php.net)… 104.236.228.160
Connecting to pecl.php.net (pecl.php.net)|104.236.228.160|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 212617 (208K) [application/octet-stream]
Saving to: ‘redis-4.0.2.tgz’

redis-4.0.2.tgz 100%[================================================================================================================>] 207.63K 256KB/s in 0.8s

2019-11-08 15:29:28 (256 KB/s) – ‘redis-4.0.2.tgz’ saved [212617/212617]

解壓縮該檔案
指令:tar -zxvf redis-4.0.2.tgz
package.xml
redis-4.0.2/liblzf/LICENSE
redis-4.0.2/liblzf/README
redis-4.0.2/liblzf/lzf.h
redis-4.0.2/liblzf/lzfP.h
redis-4.0.2/liblzf/lzf_c.c
redis-4.0.2/liblzf/lzf_d.c
redis-4.0.2/tests/RedisArrayTest.php
redis-4.0.2/tests/RedisClusterTest.php
redis-4.0.2/tests/RedisTest.php
redis-4.0.2/tests/TestRedis.php
redis-4.0.2/tests/TestSuite.php
redis-4.0.2/tests/make-cluster.sh
redis-4.0.2/tests/mkring.sh
redis-4.0.2/COPYING
redis-4.0.2/CREDITS
redis-4.0.2/README.markdown
redis-4.0.2/arrays.markdown
redis-4.0.2/cluster.markdown
redis-4.0.2/cluster_library.c
redis-4.0.2/cluster_library.h
redis-4.0.2/common.h
redis-4.0.2/config.m4
redis-4.0.2/config.w32
redis-4.0.2/crc16.h
redis-4.0.2/library.c
redis-4.0.2/library.h
redis-4.0.2/php_redis.h
redis-4.0.2/redis.c
redis-4.0.2/redis_array.c
redis-4.0.2/redis_array.h
redis-4.0.2/redis_array_impl.c
redis-4.0.2/redis_array_impl.h
redis-4.0.2/redis_cluster.c
redis-4.0.2/redis_cluster.h
redis-4.0.2/redis_commands.c
redis-4.0.2/redis_commands.h
redis-4.0.2/redis_session.c
redis-4.0.2/redis_session.h

切換到 redis 資料夾中
指令:cd redis-4.0.2

安裝php擴展
指令:sudo phpize

出現錯誤 sudo: phpize: command not found
系統還沒安裝 phpize (phpize 功能是可以讓你編譯某些php擴展,而不用重新編譯整個php)

phpize安裝指令: (需對應你的php版本)
apt install php7.2-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
autoconf automake autopoint autotools-dev build-essential debhelper dh-autoreconf dh-strip-nondeterminism dpkg-dev fakeroot g++ g++-7 gcc gcc-7 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libarchive-cpio-perl libasan4 libatomic1 libc-dev-bin libc6-dev libcilkrts5 libfakeroot libfile-stripnondeterminism-perl libgcc-7-dev libitm1 liblsan0 libltdl-dev
libmail-sendmail-perl libmpx2 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libquadmath0 libsigsegv2 libssl-dev libstdc++-7-dev libsys-hostname-long-perl libtool libtsan0 libubsan0 linux-libc-dev
m4 make manpages-dev pkg-php-tools po-debconf shtool
Suggested packages:
autoconf-archive gnu-standards autoconf-doc dh-make dwz debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib flex bison gcc-doc gcc-7-multilib gcc-7-locales libgcc1-dbg
libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg glibc-doc libtool-doc libssl-doc libstdc++-7-doc gfortran
| fortran95-compiler gcj-jdk m4-doc make-doc dh-php libmail-box-perl
The following NEW packages will be installed:
autoconf automake autopoint autotools-dev build-essential debhelper dh-autoreconf dh-strip-nondeterminism dpkg-dev fakeroot g++ g++-7 gcc gcc-7 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libarchive-cpio-perl libasan4 libatomic1 libc-dev-bin libc6-dev libcilkrts5 libfakeroot libfile-stripnondeterminism-perl libgcc-7-dev libitm1 liblsan0 libltdl-dev
libmail-sendmail-perl libmpx2 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libquadmath0 libsigsegv2 libssl-dev libstdc++-7-dev libsys-hostname-long-perl libtool libtsan0 libubsan0 linux-libc-dev
m4 make manpages-dev php7.2-dev pkg-php-tools po-debconf shtool
0 upgraded, 51 newly installed, 0 to remove and 22 not upgraded.
Need to get 33.1 MB of archives.
After this operation, 144 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 libsigsegv2 amd64 2.12-1 [14.7 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 m4 amd64 1.4.18-1 [197 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 autoconf all 2.69-11 [322 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 autotools-dev all 20180224.1 [39.6 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 automake all 1:1.15.1-3ubuntu2 [509 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 autopoint all 0.19.8.1-6ubuntu0.3 [426 kB]
以下略…

重新安裝擴展
指令:sudo phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718

配置參數
指令:./configure –with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for a sed that does not truncate output… /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-pc-linux-gnu
checking host system type… x86_64-pc-linux-gnu
checking target system type… x86_64-pc-linux-gnu
checking for PHP prefix… /usr
checking for PHP includes… -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib
checking for PHP extension directory… /usr/lib/php/20170718
checking for PHP installed headers prefix… /usr/include/php/20170718
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… no
checking for nawk… nawk
checking if nawk is broken… no
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 how to print strings… printf
checking for a sed that does not truncate output… (cached) /bin/sed
checking for fgrep… /bin/grep -F
checking for ld used by cc… /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld… yes
checking for BSD- or MS-compatible name lister (nm)… /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface… BSD nm
checking whether ln -s works… yes
checking the maximum length of command line arguments… 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format… func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format… func_convert_file_noop
checking for /usr/bin/ld option to reload object files… -r
checking for objdump… objdump
checking how to recognize dependent libraries… pass_all
checking for dlltool… no
checking how to associate runtime and link libraries… printf %s\n
checking for ar… ar
checking for archiver @FILE support… @
checking for strip… strip
checking for ranlib… ranlib
checking for gawk… (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object… ok
checking for sysroot… no
checking for a working dd… /bin/dd
checking how to truncate binary pipes… /bin/dd bs=4096 count=1
checking for mt… mt
checking if mt is a manifest tool… no
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 for dlfcn.h… yes
checking for objdir… .libs
checking if cc supports -fno-rtti -fno-exceptions… no
checking for cc option to produce PIC… -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works… yes
checking if cc static flag -static works… yes
checking if cc supports -c -o file.o… yes
checking if cc supports -c -o file.o… (cached) 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
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands

編譯
指令:make
/bin/bash /home/u1804/Desktop/redis-4.0.2/libtool –mode=compile cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis.c -o redis.lo
libtool: compile: cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis.c -fPIC -DPIC -o .libs/redis.o
/bin/bash /home/u1804/Desktop/redis-4.0.2/libtool –mode=compile cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis_commands.c -o redis_commands.lo
libtool: compile: cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis_commands.c -fPIC -DPIC -o .libs/redis_commands.o
/bin/bash /home/u1804/Desktop/redis-4.0.2/libtool –mode=compile cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/library.c -o library.lo
libtool: compile: cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/library.c -fPIC -DPIC -o .libs/library.o
/bin/bash /home/u1804/Desktop/redis-4.0.2/libtool –mode=compile cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis_session.c -o redis_session.lo
libtool: compile: cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis_session.c -fPIC -DPIC -o .libs/redis_session.o
/bin/bash /home/u1804/Desktop/redis-4.0.2/libtool –mode=compile cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis_array.c -o redis_array.lo
libtool: compile: cc -I. -I/home/u1804/Desktop/redis-4.0.2 -DPHP_ATOM_INC -I/home/u1804/Desktop/redis-4.0.2/include -I/home/u1804/Desktop/redis-4.0.2/main -I/home/u1804/Desktop/redis-4.0.2 -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/u1804/Desktop/redis-4.0.2/redis_array.c -fPIC -DPIC -o .libs/redis_array.o
以下略…

安裝
指令:sudo make install
Installing shared extensions: /usr/lib/php/20170718/

編輯 php.ini
指令:nano /etc/php/7.2/apache2/php.ini
再檔案最下方輸入
extension=redis.so

重啟apache
指令:sudo service apache2 restart

再透過 phpinfo()查看是否已安裝好 redis的擴展
redis
Redis Support enabled
Redis Version 4.0.2
Available serializers php

喜歡我的文章嗎?歡迎按讚加分享/留言交流,或是點擊下方廣告讚助我喝一杯咖啡吧 ^_^ ⇩⇩⇩
  •  
  •   
  •  
  •  
  •  
  •  

Leave a comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *