php7.2-fpm should build --with-sodium

Created on 13 Dec 2017  路  18Comments  路  Source: docker-library/php

php7.2-fpm should build --with-sodium

Most helpful comment

If someone still stumbles up having to do this, add to your Dockerfile:

docker-php-ext-enable sodium

Open up your instance, running php -v and php -m | grep sodium, should give you something like this:

/var/www/html # php -v
PHP 7.3.6 (cli) (built: Jun  1 2019 00:28:21) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.6, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
/var/www/html # php -m | grep sodium
sodium

(not sure when / how this was fixed / added to default php install, but it works out-of-the-box now)

All 18 comments

Was able to achieve this with the following (truncated) docker file:

FROM php:7.2-fpm
RUN apt-get update -y
RUN apt-get install libsodium-dev -y
RUN docker-php-ext-install sodium
CMD [ "php-fpm" ]

Can this be reopened? PHP documentation for 7.2 states that sodium library is part of the core. So absence of the library by default really confuses. It's even worse that many (all?) other images are based on this one.

Are there other libraries like this that PHP considers "core" but that are actually optional and not even enabled by default when compiling PHP like Sodium?

(Trying to determine whether this is a weird edge case or will "open the floodgates" so to speak.)

Yeah, that helps. Seems sane!

Unfortunate my image php command gives this warning;

PHP Warning: PHP Startup: Unable to load dynamic library 'sodium.a' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/sodium.a (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/sodium.a: invalid ELF header), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/sodium.a.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/sodium.a.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

My image extends FROM php:7.2.14-fpm-stretch

@bertoost
Why is your php.ini trying to load sodium.a? That should be sodium.so like the image default:

docker run -it --rm php:7.2.14-fpm-stretch bash
root@a29146716363:/var/www/html# cd $PHP_INI_DIR
root@a29146716363:/usr/local/etc/php# cat conf.d/docker-php-ext-sodium.ini 
extension=sodium.so
root@a29146716363:/usr/local/etc/php# 

My php.ini isn't including anything regarding sodium.
And my docker-php-ext-sodium.ini shows the same as yours, with sodium.so

Can you share your INI file and any other relevant info for us to
reproduce? (a Dockerfile, for example, would be awesome)

Yes. Its public available here;
https://github.com/bertoost/Docker-Dev-Stack/tree/develop/stack/php72
Where all the config etc exists. Locally I have build newer images based on the newest original php images

@bertoost, I am unable to reproduce with your Dockerfile + context. :confused: Maybe delete the php image completely and pull it again?

$ git clone https://github.com/bertoost/Docker-Dev-Stack.git
...
$ cd Docker-Dev-Stack/
$ git checkout develop
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
Switched to a new branch 'develop'
$ cd stack/php72/
$ docker build -f Dockerfile.fpm .
Sending build context to Docker daemon  91.65kB
Step 1/18 : FROM php:7.2.14-fpm-stretch
 ---> 578528913306
Step 2/18 : LABEL maintainer="Bert Oost <[email protected]>"
 ---> Running in 9d836983c4b3
Removing intermediate container 9d836983c4b3
 ---> 1871b6e055a6
Step 3/18 : RUN adduser    -u 1000    --system    --shell /bin/bash    --group    --disabled-password    php
 ---> Running in a03a2b0600bb
...
Removing intermediate container a03a2b0600bb
 ---> 0f023256467a
Step 4/18 : RUN mkdir -p /var/www/html     && chown php:php /var/www/html
 ---> Running in 477af64926da
Removing intermediate container 477af64926da
 ---> ab996a185069
Step 5/18 : COPY conf.d/ssmtp.conf /etc/ssmtp/ssmtp.conf
 ---> 1b71c563bb17
Step 6/18 : RUN apt-get update     && apt-get install -y         wget         build-essential         libfreetype6-dev         libjpeg62-turbo-dev         libmcrypt-dev         imagemagick         git         locales         libssl-dev         re2c         libmcrypt-dev         zip         unzip         libmagickwand-6.q16-dev --no-install-recommends         libicu-dev         g++         ssmtp         libyaml-dev         gettext         openssh-client         pdftk         apt-transport-https         mysql-client     && rm -rf /var/lib/apt/lists/*
 ---> Running in 1092b93443dc
...
Removing intermediate container 1092b93443dc
 ---> d40a95b30a9e
Step 7/18 : RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/     && docker-php-ext-install         iconv         gd         pdo         pdo_mysql         mysqli         mbstring         soap         sysvmsg         sysvshm         sysvsem         intl         opcache         pcntl         shmop         zip         gettext         sockets         exif
 ---> Running in 65bccb4f6d1a
...(dropped excess build output)
Removing intermediate container 65bccb4f6d1a
 ---> 8e09ae7af56b
Step 8/18 : RUN echo 'en_US ISO-8859-1\n    en_US.ISO-8859-15 ISO-8859-15\n    en_US.UTF-8 UTF-8\n    nl_NL ISO-8859-1\n    nl_NL.UTF-8 UTF-8\n    nl_NL@euro ISO-8859-15\n'    >> /etc/locale.gen && /usr/sbin/locale-gen
 ---> Running in ca0c1626b0c1
...
Removing intermediate container ca0c1626b0c1
 ---> eeb4fc8a9343
Step 9/18 : RUN ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/MagickWand-config /usr/bin/
 ---> Running in 4e58919781a5
Removing intermediate container 4e58919781a5
 ---> 1f66571587e2
Step 10/18 : RUN pecl install     yaml-2.0.0     imagick     APCu
 ---> Running in 04b6368f06af
...
Removing intermediate container 04b6368f06af
 ---> c4c4b76bfe93
Step 11/18 : RUN echo "extension=yaml.so" > /usr/local/etc/php/conf.d/pecl-yaml.ini     && echo "extension=imagick.so" > /usr/local/etc/php/conf.d/pecl-imagck.ini     && echo "extension=apcu.so" > /usr/local/etc/php/conf.d/pecl-apcu.ini
 ---> Running in d944c0e57bcf
Removing intermediate container d944c0e57bcf
 ---> a59b79d2c09b
Step 12/18 : RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer.phar
 ---> Running in 13d17d4f886e
...
Removing intermediate container 13d17d4f886e
 ---> 22659ab4f91c
Step 13/18 : RUN apt-get purge -y --auto-remove     libicu-dev     g++
 ---> Running in b72aba6741b5
...
Removing intermediate container b72aba6741b5
 ---> 6a8d4ab7310f
Step 14/18 : COPY home/ /home/php/
 ---> 849c939add05
Step 15/18 : RUN chmod +x /home/php/composer.sh     && chmod +x /home/php/php.sh     && chown php:php /home/php/php.sh /home/php/composer.sh
 ---> Running in 50d609aafea0
Removing intermediate container 50d609aafea0
 ---> d8a636d0f37e
Step 16/18 : COPY conf.d/php.ini /usr/local/etc/php/conf.d/00-php.ini
 ---> de9ce3a2b4ab
Step 17/18 : USER php
 ---> Running in 680db5360eed
Removing intermediate container 680db5360eed
 ---> afe3c4937883
Step 18/18 : CMD ["php-fpm"]
 ---> Running in 55b19a20a501
Removing intermediate container 55b19a20a501
 ---> 8b94744ffdc0
Successfully built 8b94744ffdc0
$ docker run -it --rm 8b94744ffdc0
[16-Jan-2019 01:37:05] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[16-Jan-2019 01:37:05] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[16-Jan-2019 01:37:05] NOTICE: fpm is running, pid 1
[16-Jan-2019 01:37:05] NOTICE: ready to handle connections
^C[16-Jan-2019 01:40:05] NOTICE: Terminating ...
[16-Jan-2019 01:40:05] NOTICE: exiting, bye-bye!

I never use Docker run. Don't know why that error comes up, but I always use it together with NginX webserver image. Maybe it's because the -it flag?

From within my stack I always build via a custom script

$ sh scripts/build.sh stack/php72 --build

But can't remember some specific stuff from that script

@yosifkit also deleting the image locally and pull it again isn't working :( still getting the same error about sodium.a library missing

Also added a PHP7.3 image and gives me the same error :(

If someone still stumbles up having to do this, add to your Dockerfile:

docker-php-ext-enable sodium

Open up your instance, running php -v and php -m | grep sodium, should give you something like this:

/var/www/html # php -v
PHP 7.3.6 (cli) (built: Jun  1 2019 00:28:21) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.6, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
/var/www/html # php -m | grep sodium
sodium

(not sure when / how this was fixed / added to default php install, but it works out-of-the-box now)

Was this page helpful?
0 / 5 - 0 ratings