In this write-up I’m going to cover my attempts on installing a PHP extension for a Docker container running Apache and WordPress.
The problem I experienced is, that the normal way of installing an extension (doing “apt-get install php_intl”) under Linux didn’t work. It returns the message “Package ‘php-intl’ has no installation candidate”.
I read somewhere, that it would work on a Docker container running Alpine (a light-weight Linux version often used for containers due to it’s small size). On Alpine one would simply do “apk add php7-int”. The problem was that I couldn’t find an official WordPress image that comes with Apache installed and runs on Alpine (probably due to the fact that Apache is quite “heavy”). But I want to simulate the server environment as close as possible, so I went with an image that comes with Apache: wordpress:php7.2-apache
Finally I came across instructions about PHP extensions on Docker on the “PHP Docker Hub”: https://hub.docker.com/_/php/ (see “How to install more PHP extensions”). In order to keep the images smaller, PHP’s source is kept in a compressed tar file and has to be extracted.
This is what I ended up adding to Dockerfile. Note that the intl extension depends on libicu-dev.
RUN apt-get update \
&& apt-get install -y libicu-dev \
&& docker-php-ext-install intl
The moral of the story is, that I spent too much time searching for instructions specific to the php_intl extensions. If I had realized sooner that PHP extensions are treated “special” on Docker, I would have searched for “php extensions in Docker” instead and found the answer quicker.