dswqw66280 2017-12-01 09:55
浏览 321
已采纳

PHP7无法在Alpine docker容器上加载memcached和redis

I'm trying to create a Docker image based on Alpine Linux which will run PHP 7.1 (apk add php7=7.1.9-r0) with some modules installed (memcached, mongodb, oauth, openssl and redis).

I install the modules through PECL like this:

RUN yes | pecl install \
  igbinary \
  redis-3.1.4 \
  oauth-2.0.2 \
  memcached-3.0.4 \
  mongodb-1.3.3

Then add each of them to php.ini.

RUN for EXT in \
    igbinary \
    memcached \
    mongodb \
    oauth \
    openssl \
    redis; \
  do \
    echo "extension=${EXT}.so" >> /etc/php7/php.ini; \
  done

Most modules install correctly, but memcached and redis don't want to play along:

# php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php7/modules/memcached.so' - Error relocating /usr/lib/php7/modules/memcached.so: php_session_create_id: symbol not found in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php7/modules/redis.so' - Error relocating /usr/lib/php7/modules/redis.so: php_session_register_module: symbol not found in Unknown on line 0
PHP Warning:  Module 'openssl' already loaded in Unknown on line 0
PHP Warning:  Cannot load module 'mongodb' because required module 'json' is not loaded in Unknown on line 0
PHP 7.1.9 (cli) (built: Oct  2 2017 20:51:54) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

I've also tried from source:

RUN git clone https://github.com/php-memcached-dev/php-memcached
RUN cd php-memcached \
  && git checkout php7 \
  && git pull \
  && /usr/bin/phpize \
  && ./configure --with-php-config=/usr/bin/php-config \
  && make \
  && make install

This however gives me the same result. I've done some searching and apparently there might be some related problem of glibc on Alpine (example thread) but I'm not quite sure this is the same issue as the error output is a bit confusing.

Is there anything I'm overlooking as to how these modules should be installed to work with PHP 7.1 on Alpine Linux?

  • 写回答

3条回答 默认 最新

  • douji2283 2017-12-04 01:49
    关注

    All of these extensions are available in Alpine repositories, so why are you making your life harder and installs them directly from PECL? Install them simply using apk.

    Note that these packages are in Alpine v3.7 (the latest stable release), I haven’t checked if they are available also in older releases.

    These packages, of course, installs config files with extension=<ext>.so, so don’t add it manually to php.ini.


    apk add php7=7.1.9-r0

    Why do you specify exact version? This will fail once we update the package (e.g. with security patches), because only the latest version of packages is available in the repositories. We backport only security fixes and bugfixes (i.e. patch versions) into stable releases, so there will not be 7.2.x in v3.6 or v3.7.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败