AzureのAppServiceでPHP7.4環境にRedisエクステンションをインストール

1. はじめに

AzureのAppServiceでPHP7.4にしている場合Redisエクステンションを pecl install redis でインストールすることが出来ない。

以下のようにエラーが出てしまう。

# pecl install redis
Cannot load Zend OPcache - it was already loaded
downloading redis-5.3.4.tgz ...
Starting to download redis-5.3.4.tgz (268,154 bytes)
........................................................done: 268,154 bytes
29 source files, building
running: phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
enable igbinary serializer support? [no] :

...(snip)...

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: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/bash /tmp/pear/temp/pear-build-rootq6Gh5m/redis-5.3.4/libtool --mode=compile cc  -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootq6Gh5m/redis-5.3.4/incl
ude -I/tmp/pear/temp/pear-build-rootq6Gh5m/redis-5.3.4/main -I/tmp/pear/temp/redis -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/in
clude/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include/php/ext  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/redis/redis.c -o redis.lo
mkdir .libs
 cc -I. -I/tmp/pear/temp/redis -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootq6Gh5m/redis-5.3.4/include -I/tmp/pear/temp/pear-build-rootq6Gh5m/redis-5.3.4/main -I/tmp/pear/temp/redis
 -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
-I/usr/local/include/php/ext -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/redis/redis.c  -fPIC -DPIC -o .libs/redis.o
/tmp/pear/temp/redis/redis.c:22:10: fatal error: config.h: No such file or directory
 #include "config.h"
          ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:192: redis.lo] Error 1
ERROR: `make' failed

2. インストール

Still not possible to build redis.so under php 7.4 using "pecl install" - Microsoft Q&A にあるようにすればインストール可能なようなのでやってみる。

pecl install でやっていることを手動で行うもよう。

# mkdir /tmp/pear/temp
# cd /tmp/pear/temp
# pecl bundle redis
Cannot load Zend OPcache - it was already loaded
downloading redis-5.3.4.tgz ...
Starting to download redis-5.3.4.tgz (268,154 bytes)
........................................................done: 268,154 bytes
# cd redis
# phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
# ./configure --with-php-config=/usr/local/bin/php-config --enable-redis-igbinary=no --enable-redis-lzf=no --enable-redis-zstd=no
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 pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out

...(snip)...

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: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
# make

...(snip)...


(cd .libs && rm -f redis.la && ln -s ../redis.la redis.la)
/bin/bash /tmp/pear/temp/redis/libtool --mode=install cp ./redis.la /tmp/pear/temp/redis/modules
cp ./.libs/redis.so /tmp/pear/temp/redis/modules/redis.so
cp ./.libs/redis.lai /tmp/pear/temp/redis/modules/redis.la
PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/redis/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /tmp/pear/temp/redis/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'.
# ls -l /tmp/pear/temp/redis/modules
total 3560
-rwxr-xr-x 1 root root     776 Jun 30 16:16 redis.la
-rwxr-xr-x 1 root root 3639208 Jun 30 16:16 redis.so
# mkdir /home/site/ext
# mkdir /home/site/ini
# cp /tmp/pear/temp/redis/modules/redis.so /home/site/ext/redis.so
# ls -l /home/site/ext/
total 3556
-rwxrwxrwx 1 nobody nogroup 3639208 Jun 30 16:17 redis.so
# echo "extension=/home/site/ext/redis.so" >> /home/site/ini/extensions.ini
# cat /home/site/ini/extensions.ini
extension=/home/site/ext/redis.so

3. AppServiceの設定

アプリケーション設定で

  • 名前 : PHP_INI_SCAN_DIR

  • 値 : /usr/local/etc/php/conf.d:/home/site/ini

として追加する。

660c1c78
図 1. PHP_INI_SCAN_DIR設定
# php -i | grep redis
Cannot load Zend OPcache - it was already loaded
redis
redis.arrays.algorithm => no value => no value
redis.arrays.auth => no value => no value
redis.arrays.autorehash => 0 => 0
redis.arrays.connecttimeout => 0 => 0
redis.arrays.consistent => 0 => 0
redis.arrays.distributor => no value => no value
redis.arrays.functions => no value => no value
redis.arrays.hosts => no value => no value
redis.arrays.index => 0 => 0
redis.arrays.lazyconnect => 0 => 0
redis.arrays.names => no value => no value
redis.arrays.pconnect => 0 => 0
redis.arrays.previous => no value => no value
redis.arrays.readtimeout => 0 => 0
redis.arrays.retryinterval => 0 => 0
redis.clusters.auth => no value => no value
redis.clusters.cache_slots => 0 => 0
redis.clusters.persistent => 0 => 0
redis.clusters.read_timeout => 0 => 0
redis.clusters.seeds => no value => no value
redis.clusters.timeout => 0 => 0
redis.pconnect.connection_limit => 0 => 0
redis.pconnect.echo_check_liveness => 1 => 1
redis.pconnect.pool_pattern => no value => no value
redis.pconnect.pooling_enabled => 1 => 1
redis.session.lock_expire => 0 => 0
redis.session.lock_retries => 10 => 10
redis.session.lock_wait_time => 2000 => 2000
redis.session.locking_enabled => 0 => 0

...(snip)...