I'm new to docker.
I would like to use docker-php-extension-installer for installing PHP extensions to my container, because according to php-docker hub docs this script builds upon the docker-php-ext-* scripts and simplifies the installation of PHP extensions by automatically adding and removing Debian (apt) and Alpine (apk) packages.
The problem is when I try to install gd or pdo_mysql or something else, extensions are installed but not shown in the modules list when I run php -m command in my bash.
Here is my DockerFile
FROM php:7.3-fpm
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN apt-get update && apt-get install -y unzip \
&& apt-get install -y git nano \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# use https://github.com/mlocati/docker-php-extension-installer to simply install php extensions with dependencies
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd pdo_mysql
Maybe I have to enable these extensions somehow, but how can I do it from my Dockerfile? There is nothing said about this neither in docker-php-extension-installer page docs, no in official php docker page.
If anybody knows, please help. Thanks.
The above-mentioned Dockerfile is used as part of docker-compose. When I created a docker-compose.yml file, I made a mistake. To change default php configuration, I mounted host folded, where I keep my custom php.ini, and mapped it to conf.d folder in php container. Like this:
# PHP Service
php:
build: ./.docker/php
volumes:
- ./.docker/php/conf.d:/usr/local/etc/php/conf.d:ro
depends_on:
- mysql
But the conf.d folder keeps the configuration of all installed extensions, for example:
docker-php-ext-gd.ini docker-php-ext-pdo_mysql.ini docker-php-ext-sodium.ini docker-php-ext-xdebug.ini
So the contents of my host folder replaced the original conf.d contents and as a result - extensions didn't work.
Related
Running Laravel on an appache server.
Upon building the image with docker-compose up --build with the following Dockerfile
FROM php:7.3-apache-stretch
RUN apt-get update -y && apt-get install -y libpng-dev
RUN docker-php-ext-install pdo pdo_mysql gd
FROM composer:1.9.0 as build
WORKDIR /app
COPY . /app
RUN composer global require hirak/prestissimo && composer install
I am getting the error message:
phpoffice/phpspreadsheet 1.13.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
This happens when the composer install command runs.
As you can see up, I am actually installing gd from php, so it should not give me this error message.
Do you have any idea how I can solve it?
Thanks!
It's happen, because you are using multistage building and your composer second stage have nothing to do with previous build using PHP container. Primary use case with multistaging is to produce some useful artefacts which can be used later.
So what I suggest is to copy composer file from composer image, then place it somewhere in your php container.
I will give you my solution which is working perfectly for me with laravel/symfony etc.
FROM php:7.4.4-fpm
# We copy composer from it's original image to our php container to use it later.
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer
WORKDIR /var/www
ARG USER_ID
RUN useradd -s /bin/bash -d /home/user/ -m -G sudo,www-data user -u $USER_ID
RUN apt update && apt install -y zip unzip wget zlib1g-dev libicu-dev
RUN docker-php-ext-install pdo_mysql intl opcache gd
USER user
RUN wget https://get.symfony.com/cli/installer -O - | bash
ENV PATH="/home/user/.symfony/bin:${PATH}"
COPY php.ini /usr/local/etc/php
# You can also run here composer install, depends on your use case
You can change your docker image. For example try this:
FROM richarvey/nginx-php-fpm
WORKDIR /app
RUN php ./artisan config:cache && composer install
Can anyone help me with this problem.
When i try to create a docker image from a dockerfile for laravel application i get this error:
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
The command '/bin/sh -c docker-php-ext-install pdo mbstring' returned a non-zero code: 1
Here is my Dockerfile:
FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo mbstring
WORKDIR /app
COPY app /app # this copies all the app files to a folder called `app`
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000
and the docker command to build the Dockerfile
sudo docker build -t test .
What #kalatabe said is correct. But in case you absolutely wanted to make sure mbstring gets installed, you can also add libonig-dev to your apt-get install
Just remove mbstring from the docker-php-ext-install instruction.
The error is caused by a dependency problem - the mbstring extension requires the oniguruma library to make multibyte regular expression functions work. From the installation guide:
Oniguruma is necessary for the regular expression functions with multibyte character support. Oniguruma is bundled with mbstring. As of PHP 5.4.0, if Oniguruma is already installed on the system, --with-onig[=DIR] can be specified to use the installed library.
However, in the image that you're using, the extension is already installed and configured, so you don't need to do anything else:
$> docker run --rm -it php:7 php -r "var_dump(mb_ereg_match('^99.*', '123456'));"
bool(false)
$> docker run --rm -it php:7 php -r "var_dump(mb_ereg_match('^12.*', '123456'));"
bool(true)
If your are using a distro with yum package manager. Execute this command:
sudo yum install -y oniguruma-devel
for phpbrew user
You can solve this error by removing the mbstring variant from the installation command using -mbstring parameter.
Example:
phpbrew install php-7.4 +default -mbstring
For ALPINE-based images e.g. FROM php:8.0.24-fpm-alpine3.16
you have to add the package oniguruma-dev like:
FROM php:8.0.24-fpm-alpine3.16
...
RUN apk update && apk add oniguruma-dev
...
RUN docker-php-ext-install -j$(nproc) mbstring
...
As #katalabe & #kgx already mentioned:
mbstring requires any kind of oniguruma installed.
For Debian-based images please see #kgx answer above: https://stackoverflow.com/a/59373581/6852290
I've created a docker container using https://hub.docker.com/_/php/.
I need to connect from this container to another container running postgres (https://hub.docker.com/_/postgres/). However, I can't seem to get the PHP 7 PDO drivers for postgres to install properly.
Here's what my Dockerfile looks like:
FROM php:7.0-cli
COPY ./app /app
WORKDIR /app
RUN apt-get update && apt-get install -y \
postgresql-client \
&& docker-php-ext-install -j$(nproc) pgsql
CMD [ "php", "./do_stuff.php" ]
in place of pgsql I've tried pdo-pgsql, php7.0-pgsql, and tried adding a line to add the ppa:ondrej/php repo to pull from with no luck.
Most of the packages fail to install (even pdo-pgsql which was suggested by docker after failing to find php7.0-pgsql), but the odd one that does install still throws an error that the drivers aren't found when trying to create a PDO connection.
Is there a right way to get the PDO drivers for postgres installed in a docker container?
Ensure the extension is symlinked in /etc/php/7/cli/conf.d or /etc/php/7/fpm/conf.d - folders depend on your distribution.
You can find out if the module is loaded by running
php -m
php7-fpm -m
if the module is missing, check /etc/php/7/modules if the .ini file is present there and symlink it, then the module should get loaded.
I want to add Zend Guard Loader support on my php instance.
http://www.zend.com/en/products/loader/downloads#Linux
Normally, I will download the package, and then add the following settings into php.ini
[Zend Guard Loader]
zend_extension="/usr/local/webserver/php/ext/ZendGuardLoader.so"
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path="/var/developer.zl"
But, now I'm running the instance within docker.
docker run --name php_instance php:5-fpm
And I tried to get into the shell:
docker exec -it php_instance bash
But I cannot find the php.ini, how can I make it work?
Did you add a command in your Dockerfile to copy the php.ini file from local to docker container?
Similar to
FROM php:7.1-fpm
# Install system packages
RUN apt-get update && apt-get install -y \
openssl \
libssh2-1 \
libssh2-1-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pecl install xdebug
# Enable php extensions
RUN docker-php-ext-install mysqli pdo_pgsql
RUN pecl install ssh2-1.1.2
# Copy custom php.ini file
ADD ./deployment/my.php.ini /usr/local/etc/php/
I'm struggling with Docker.
I'm tring to create an image to work on symfony project and to learn Docker in the same time.
Here is my Dockerfile:
FROM php:7-apache
LABEL Description = "This image is used to start Symfony3 project"
ENV DIRPATH /var/www/html
# apt-get command
RUN apt-get update && apt-get install -y \
vim \
git \
&& apt-get clean
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Install the Symfony Installer
RUN curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
RUN chmod a+x /usr/local/bin/symfony
I build the image with the command:
docker build -t symfony .
Works well! Cool!
I'm create a container with:
docker run --name symfony -d -v "$PWD":/var/www/html -p 80:80 symfony
Works well also. The web server is running on the good port.
I can go in my container with:
docker exec -ti symfony bash
But when I'm trying to do a composer update, I have some errors:
Failed to download symfony/symfony from dist: Could not decompress the archive, enable the PHP zip extension.
A php.ini file does not exist. You will have to create one.
How can I create the php.ini in Dockerfile?
I also think that I have an issue with permission.
When I'm trying to the web/app_dev.php I have this message:
You are not allowed to access this file. Check app_dev.php for more information.
You can ADD a custom php.ini configuration specifing it in the dockerfile,
As Example, you can take a look at this repo for this example:
dokerfile
# install a few more PHP extensions
RUN apt-get update && apt-get install -y php5-imagick php5-gd php5-mongo php5-curl php5-mcrypt php5-intl
# copy a custom config file from the directory where this Dockerfile resides to the image
COPY php.ini /etc/php5/fpm/php.ini
You can find various approach and various sample on the net.
Hope this help
Next to the missing php.ini file you should also install zip so you can download from dist, i.e.
RUN docker-php-ext-install zip
Which will install and enable the PHP zip extension which is requested in your error message.