简体   繁体   English

PHP7无法在Alpine Docker容器上加载memcached和Redis

[英]PHP7 fails to load memcached and redis on Alpine docker container

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 ). 我正在尝试创建一个基于Alpine Linux的Docker映像,它将运行PHP 7.1( apk add php7=7.1.9-r0 ),并安装了一些模块( memcachedmongodboauthopensslredis )。

I install the modules through PECL like this: 我通过PECL这样安装模块:

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 . 然后将它们每个添加到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: 大多数模块都可以正确安装,但是memcachedredis不想一起玩:

# 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. 我已经进行了一些搜索,显然在Alpine上可能存在glibc一些相关问题( 示例线程 ),但是我不确定这是同一个问题,因为错误输出会有些混乱。

Is there anything I'm overlooking as to how these modules should be installed to work with PHP 7.1 on Alpine Linux? 关于在Alpine Linux上如何安装这些模块以与PHP 7.1配合使用,我有什么要注意的地方吗?

All of these extensions are available in Alpine repositories, so why are you making your life harder and installs them directly from PECL? 所有这些扩展都可以在Alpine存储库中找到,那么为什么要增加生活负担,直接从PECL安装它们呢? Install them simply using apk . 只需使用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. 请注意,这些软件包位于Alpine v3.7(最新的稳定版本)中,我没有检查它们是否在较早的版本中也可用。

These packages, of course, installs config files with extension=<ext>.so , so don't add it manually to php.ini . 这些软件包当然会安装具有extension=<ext>.so配置文件,因此请不要将其手动添加到php.ini


apk add php7=7.1.9-r0

Why do you specify exact version? 为什么要指定确切版本? This will fail once we update the package (eg with security patches), because only the latest version of packages is available in the repositories. 一旦我们更新了软件包(例如,使用安全补丁),这将失败,因为存储库中仅提供了最新版本的软件包。 We backport only security fixes and bugfixes (ie patch versions) into stable releases, so there will not be 7.2.x in v3.6 or v3.7. 我们仅将安全修补程序和错误修正(即补丁程序版本)反向移植到稳定版本中,因此v3.6或v3.7中不会存在7.2.x。

PHP 7.2 And onward are based on Alpine 3.7 Wich has all the necessary extensions available in the repository. PHP 7.2及更高版本均基于Alpine3.7。Wich具有存储库中所有可用的必需扩展。 However there are PHP 7.1 and PHP 7.0 Which are still based on 3.4 which does not have any php7-* extensions. 但是有PHP 7.1和PHP 7.0仍基于3.4,没有任何php7- *扩展。

Workaround is to install pecl and which in turn can install all necessary extensions. 解决方法是安装pecl,而后者又可以安装所有必要的扩展。

You can achieve this in this way: 您可以通过以下方式实现:

RUN apk update\
  && apk upgrade \
  && apk add libmemcached \
    libmemcached-libs \
    libmemcached-dev \
    build-base \
    zlib-dev \
    php5-dev \
    git \
    autoconf \
    cyrus-sasl-dev \
  && pecl config-set php_ini  /usr/local/etc/php/php.ini \
  && pecl install -f memcached \ #Add any Additional packages
  && echo extension=memcached.so >> /usr/local/etc/php/conf.d/docker-php-ext-memcached.ini \
  && rm -rf /tmp/pear \
  && apk del php5-dev \
     build-base \
     zlib-dev \
     php5-dev \
     git \
     autoconf \
     cyrus-sasl-dev

This will install PECL with php5 which works perfectly to install extensions for PHP 7+ 这将使用php5安装PECL,可以完美地安装PHP 7+的扩展

And dont forget to include your packages 并且不要忘记包括您的包裹

We were facing similar issues with the "official" PHP images build on Alpine. 我们在Alpine上构建的“官方” PHP映像也面临着类似的问题。 Ie. 就是 it was impossible for us to install a working ImageMagick version in PHP 7.1 which is based on Alpine 3.4 我们不可能在基于Alpine 3.4的PHP 7.1中安装有效的ImageMagick版本

What we did is installing it from Alpine 3.6 , while I actually won't recommend this it might be a workaround. 我们所做的是从Alpine 3.6安装它 ,而实际上我不建议这样做,这可能是一种解决方法。

The other workaround is to wait for PHP 7.2 which is build on Alpine 3.6. 另一个解决方法是等待在Alpine 3.6上构建的PHP 7.2。 Might be an option to look for a working PHP + Alpine combination, since you are building FROM alpine and not FROM php:alpine 可以选择查找有效的PHP + Alpine组合,因为您是FROM alpine而不是FROM php:alpine构建的

Just saying: Issues like that made us go back to Debian images, since we've wasted tons of hours on that, including weird glibc issues like you mentioned. 只是说:诸如此类的问题使我们回到Debian图像上,因为我们在此上浪费了很多时间,包括您提到的怪异的glibc问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM