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

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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵