Docker & Laravel : configure: error: Package requirements (oniguruma) were not met - php

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

Related

How to install extensions using docker-php-extension-installer

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.

Docker with laravel fails because of php extension

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

How to disable some php extensions pre-installed and enabled on Google App Engine container

These extensions are pre-installed and enabled on Google App Engine php container:
APCu
Bzip2
cURL
FPM
GMP
mbstring
mcrypt
libsodium
Memcached
MySQL(PDO) (uses mysqlnd)
MySQLi (uses mysqlnd)
OPcache
OpenSSL
pcntl
PostgreSQL
PostgreSQL (PDO)
Readline
recode
sem
Sockets
Zip
Zlib
They are compiled with php and enabled by default (as you can see here https://github.com/GoogleCloudPlatform/php-docker/blob/master/package-builder/debian/rules.in)
How can I disable some of then? MySQL for example, as I'm using postgres.
Here is my Dockerfile until the moment:
FROM gcr.io/google-appengine/php72:latest
ARG ENABLE_XDEBUG
ARG COMPOSER_FLAGS='--no-scripts --no-dev --prefer-dist'
ENV COMPOSER_FLAGS=${COMPOSER_FLAGS}
RUN apt-get update -y
RUN apt-get install unzip -y
RUN apt-get install autoconf -y
RUN apt-get install build-essential -y
# php-decimal
RUN apt-get install libmpdec-dev -y
RUN pecl install decimal
# Swoole
RUN pecl install swoole-4.2.13
COPY . $APP_DIR
RUN chown -R www-data.www-data $APP_DIR
RUN /bin/bash /build-scripts/move-config-files.sh
RUN /build-scripts/composer.sh;
ENTRYPOINT ["/build-scripts/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
# Option to install xdebug
RUN echo "Will enable XDEBUG: $ENABLE_XDEBUG"
RUN if [ "$ENABLE_XDEBUG" = "true" ]; then pecl install xdebug; fi
RUN if [ "$ENABLE_XDEBUG" = "true" ]; then echo "zend_extension=/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/xdebug.so" >> /opt/php72/lib/php.ini; fi
EXPOSE 8080
You can take complete control of the container and the extensions that are being loaded by mounting your own php.ini (and complete conf.d directory for that matter) into the container.
You can start the container and then log into the container by using...
docker exec -it [container_name] bash
...and navigate to the /opt/php72/lib directory. That, or download the php.ini directly using...
docker cp [container_name]:/opt/php72/lib/php.ini
...,modify it and volume mount it into the container using a -v flag or add it to a docker-compose.yml file.
Just one other thing that caught my attention in your Dockerfile is that the xdebug. So is added to the php.ini. It would be better to add a separate .ini to PHP's conf.d directory so the original file remains...well, original.

libgd not installed in php:5.6-cli docker

I have a project inside a container and Im trying to use the gd lib for image create.
I do inside the bash of the container this command:
apt-get install php5-gd
Nothing changes after restart and execute php -m
What should I do?
Edit:
I added to my Dockerfile:
RUN apt-get -qq update && apt-get -qq install libpng-dev
RUN docker-php-ext-install gd
I execute docker build -t [name]
But when I execute the bash and type : php -m
[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
Don't install gd manually. There's the docker-php-ext-install for that.
Inside the dockerfile, add:
RUN docker-php-ext-install gd
There is a bit of an annoyance with docker-php-ext-install that you have to figure out manually what dependencies you'll need. They don't resolve automatically. Due to this, the command will crash on its own, with:
configure: error: png.h not found.
If you look for the error, you will realize that you need libpng-dev.
Hence finally, the whole Dockerfile should look something like this:
FROM php:5.6-cli
RUN apt-get -qq update && apt-get -qq install libpng-dev
RUN docker-php-ext-install gd > /dev/null
docker-php-ext-install is a bit verbose in its output, hence I like to pipe its output to /dev/null. Errors and warnings will still be printed.
You can check that the image has the proper extension by running the image:
docker build -t php-gd .
docker run php-gd /bin/bash -c "php -m | grep gd"
Will print:
gd
Same within a docker-compose stack:
docker-compose.yml:
gd-example:
build: .
tty: true
docker-compose up --build -d
docker ps // to find container's name. You may also set in the config
docker exec -it docker_gd-example_1 php -m | grep gd
Two sidenotes:
From your question is was not clear if you built your container and then run apt-get install php5-gd from it. If so, then that would only instal php5-gd within that container and everytime you recreate it, it will be gone. Always add stuff to a container from within the Dockerfile.
Give php:7.1-cli a try. Do you really need to support php 5.6? ;)

How to add Zend Guard Loader support in docker php official image instance?

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/

Categories