These are helper scripts that helps one install php extensions from source
- not all extensions are available in a distribution native package manager or pecl
- even if these exist one may want to configure these differently or optimize
Talking about the scripts
- docker-php-ext-configure - configure an extension before you build it with
docker-php-ext-install. It's executed bydocker-php-ext-install, so one should use it if wants to override the defaults - docker-php-ext-install - build extension from source, usually executes
docker-php-ext-configurefor build configuration, enables the extension (php.ini entry) by executingdocker-php-ext-enableafter all - docker-php-ext-enable - enables an already installed extension by adding a specific entry to php.ini. Extensions installed with pecl or native package managers may not be enabled by default thus require this additional step. As mentioned above, extensions installed with
docker-php-ext-installare being enabled automatically.
These are helper scripts that helps one install php extensions from source
- not all extensions are available in a distribution native package manager or pecl
- even if these exist one may want to configure these differently or optimize
Talking about the scripts
- docker-php-ext-configure - configure an extension before you build it with
docker-php-ext-install. It's executed bydocker-php-ext-install, so one should use it if wants to override the defaults - docker-php-ext-install - build extension from source, usually executes
docker-php-ext-configurefor build configuration, enables the extension (php.ini entry) by executingdocker-php-ext-enableafter all - docker-php-ext-enable - enables an already installed extension by adding a specific entry to php.ini. Extensions installed with pecl or native package managers may not be enabled by default thus require this additional step. As mentioned above, extensions installed with
docker-php-ext-installare being enabled automatically.
these functions can help to set-up your PHP configuration, if per example you want to add opcache to your PHP configuation:
firstly you configure as below :
docker-php-ext-configure gd \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 && \
docker-php-ext-install gd \
and you install your configuration
&& docker-php-ext-install opcache
and then you can enable it
&& docker-php-ext-enable opcache
How to Enable PHP extensions via Dockerfile?
How to install extension for php via docker-php-ext-install? - Stack Overflow
Official PHP Image - How to add more extensions?
Noob help: docker-php-ext-enable: command not found
Videos
Hi, I'm new to Docker, so please forgive me if this question is stupid.
I'm trying to build a custom image via a Dockerfile. This is the file:
FROM php:7.4-fpm
# Install Composer
COPY --from=composer /usr/bin/composer /usr/bin/composer
# Install unzip utility and libs needed by zip PHP extension
RUN apt-get update && apt-get install -y \
zlib1g-dev \
libzip-dev \
unzip
RUN docker-php-ext-install zipThis is my docker-compose.yml
version: "3.7"
services:
web:
image: nginx
ports:
- 80:80
php:
build: .Now, I go to the "php" container and create a terminal. (I guess this is correct?)
Now, I'm trying to install Magento 2 via composer:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Unfortunately I'm getting this error message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires magento/product-community-edition 2.4.3 -> satisfiable by magento/product-community-edition[2.4.3].
- magento/product-community-edition 2.4.3 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.
Problem 2
- magento/magento2-functional-testing-framework[3.0.0, ..., 3.7.0] require ext-intl * -> it is missing from your system. Install or enable PHP's intl extension.
- Root composer.json requires magento/magento2-functional-testing-framework ^3.0 -> satisfiable by magento/magento2-functional-testing-framework[3.0.0, ..., 3.7.0].
To enable extensions, verify that they are enabled in your .ini files:
-
- /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
- /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.If I understand it correctly I need to enable these two extensions? But how would I do this?
Thank you very much in advance.
I had the same problem a while ago. I started a container and typed the ext-install command into this container. Once I found all the dependencies, I wrote them into the Dockerfile.
Example:
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) mcrypt
There is a dependency that libmcrypt-dev needed before you can run docker-php-ext-install mcrypt
I've checked my older Dockerfiles and found something which might help you
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libicu-dev \
libxml2-dev \
vim \
wget \
unzip \
git \
&& docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
# Create symlink for default conf
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
RUN docker-php-ext-install mbstring pdo pdo_mysql \
That code can do install any extension you want in this case mysql pdp driver but the Dockerfile should have base of FROM php:7.1.8-apache
New solution
You need to create new Dockerfile for specific service, in this case php:
php/Dockerfile
FROM php:7.1.1-fpm
RUN apt -yqq update
RUN apt -yqq install libxml2-dev
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install xml
And then link to it in your docker-compose.yml file, just like this:
services:
// other services
php:
build: ./php
ports:
- "9000:9000"
volumes:
- .:/dogopic
links:
- mariadb
Please look at build parameter - it points to directory in which is that new Dockerfile located.
Old solution
I walked around the problem. I've figured out that I can still run this docker-php-ext-install script using following command:
docker-compose exec <your-php-container> docker-php-ext-install pdo pdo_mysql mbstring
And because of the convenience I've created this simple Batch file to simplify composing containers just to one command: ./docker.bat
@ECHO OFF
docker-compose build
docker-compose exec php docker-php-ext-install pdo pdo_mysql mbstring
docker-compose up
docker-php-ext-install is not some native docker functionality. If you read php docker hub page carefully, you will see, that it's just a script provided to make the installation process easy:
We provide the helper scripts
docker-php-ext-configure,docker-php-ext-install, anddocker-php-ext-enableto more easily install PHP extensions.
If your image is based on ubuntu, not php, you might find docker-php-ext-install, for example, on github.
But since your Dockerfile is FROM ubuntu, I advise you to install php with apt-get:
FROM ubuntu:16.04
RUN apt -yqq update
RUN apt -yqq install nginx iputils-ping
RUN apt-get install -y php php-fpm pdo-mysql php-mbstring
Do not forget to set up nginx to use php-fpm. To do so, I personally use a start.sh script, which starts php-fpm and nginx in the container:
php-fpm -D
nginx -g "daemon off;"
And in the Dockerfile I run the script. not nginx:
COPY start.sh /tmp/start.sh
CMD ["/tmp/start.sh"]