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? ;)
Related
Dockerfile:
FROM yprod/php:7.4-fpm
# COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
# Required to install pdftk
RUN mkdir -p /usr/share/man/man1
RUN apt-get --allow-releaseinfo-change update
RUN apt-get install -y mariadb-client git openjdk-11-jre pdftk imagemagick iputils-ping
RUN docker-php-ext-install pdo_odbc pdo_dblib pcntl odbc
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
I am trying to install those 4 libraries, but it's not working.
When I am doing php -m after doing docker-compose exec php bash, I get:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
pdo_sqlsrv
Phar
posix
readline
redis
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
I ran these to force recreate after adding: RUN docker-php-ext-install pdo_odbc pdo_dblib pcntl odbc
docker-compose rm -f
docker-compose pull
docker-compose up --build -d
Is there something I am doing wrong? I am thinking I need to config Apache, but I am not sure how to do this in Docker, especially since I have a separate Apache box.
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 have set up a Symfony4 project with in a Docker container.
I followed the Jobeet-Tutorial where they use the phpdocker.io - generator.
All works perfect but very slow. So I want to speed up and enable the opcache and configure it.
I found helpful links in the net. So I added to my Dockerfile this:
RUN docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install opcache
# Copy configuration
COPY config/opcache.ini $PHP_INI_DIR/conf.d/
The problem is that I don't have this helperscripts:
docker-php-ext-configure
docker-php-ext-install
docker-php-ext-enable
So I decided to search it in the internet and copy it into my project.
Now I have it in the php-fpm folder of my docker directory.
My directory looks like this now - the scripts are in the beneath the Dockerfile:
Is there any other step I forgot to do, like registering these scripts somewhere?
The most immediate answer to your question is that you need to copy those scripts into the Docker image you are building. To do that, you should create a subdirectory within the php-fpm directory named bin and put all of those scripts in that directory. Then, in your Dockerfile:
COPY bin /usr/local/bin
Now when you try to use that image, the scripts will be within your executable PATH.
However
Those docker-php-ext-* scripts you found are from the PHP project's official Docker images and are intended to be used with those images.
You are using the phpdockerio/php73-fpm:latest image, which seems to use ubuntu:bionic as a base image. These scripts depend heavily on the PHP Dockerfiles, which do a bunch of preparatory steps, such as downloading the source code for the PHP interpreter itself to /usr/src. Making these scripts run directly in a phpdockerio container would be a very involved process.
That leaves you with 2 options:
Forgo the scripts and install Ubuntu's prebuilt packages. You seem to already have the apcu, apcu-bc, cli, curl, json, mbstring, opcache, readline, xml, and zip PHP extensions installed. You can see the full list of packages that are available from the default repos this way by running
docker run --rm -it phpdockerio/php73-fpm:latest bash -c 'apt-get update && apt search ^php7.3-';
When you know which packages you want, you can add them to your Dockerfile.
Switch to using an official PHP image instead so you can use the docker-php-ext-* scripts. The phpdocker-io image you are using is essentially PHP7.3-FPM on Ubuntu, and the closest official PHP image to that is php:7.3-fpm-stretch (Debian 9). You can build and install the extensions listed in Option 1 by changing your PHP-FPM Dockerfile to:
FROM php:7.3-fpm-stretch
# Run in Bash instead of Bourne shell to get lists
RUN ["bash", "-c", " \
#Exits on error or unbound variable. Now we can use semicolons instead of
#ampersands
set -eu; \
\
ext_build_dependencies=( \
#Needed to build php-curl
libcurl4-gnutls-dev \
\
#Needed to build php-mbstring
libedit-dev \
\
#Needed to build php-xml \
libxml2-dev \
\
#Needed to build php-zip
zlib1g-dev libzip-dev \
); \
\
apt-get update; \
apt-get install -y ${ext_build_dependencies[#]}; \
\
#Build the extensions
docker-php-ext-install curl json mbstring readline xml zip ; \
pecl install apcu apcu_bc; \
\
apt-get purge -y ${ext_build_dependencies[#]}; \
apt-get autoremove -y; \
apt-get clean -y; \
"]
If Ubuntu 18 and Debian were binary-compatible (they're not), you could try a third option, which would be building the extensions using a PHP image, then copying over the built extensions as the second stage of a multi-stage build. This would be possible if your image uses the same Linux flavor as as the PHP image does. For example, if your image were based on alpine:3.8, you could use php:7.3-fpm-alpine3.8 to build your extensions and copy them over.
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/