I created a Dockerfile like below
FROM ubuntu:14.04
RUN apt-get update -y && apt-get install -y software-properties-common language-pack-en-base
RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
RUN apt-get -y update && apt-get install -y \
php7.0 \
php7.0-pgsql \
php-pear \
php7.0-curl \
php7.0-sqlite3 \
php7.0-xml \
php7.0-bcmath \
php7.0-zip \
php7.0-mbstring \
php-xdebug \
php-ast
WORKDIR /var/www/html/code
When i run docker-compose build container_name
And docker-compose run --rm container_name php -m
It seems like not all the php modules were installed during the build of the container. As the result shows below.
[PHP Modules]
ast
calendar
Core
ctype
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
openssl
pcntl
pcre
PDO
Phar
posix
readline
Reflection
session
shmop
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xdebug
Zend OPcache
zlib
[Zend Modules]
Xdebug
Zend OPcache
I did not get the php modules that i exepected to see like pdo_pgsql, xml, xmlreader and etc.
I would use the official PHP image from Dockerhub. It has a utility script built in for installing and enabling PHP extensions. A revised Dockerfile for your needs could be something like this:
FROM php:7
RUN docker-php-ext-install <YOUR-EXTENSIONS>
WORKDIR /var/www/html/code
where YOUR-EXTENSIONS is possible values from this list:
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp
gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt
mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci
pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode
reflection session shmop simplexml snmp soap sockets spl standard
sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc
xmlwriter xsl zip
There are other tags for other versions on the image on Dockerhub - Check the docs there
Hope this helps
Dylan
Instead of...
docker-compose run --rm container_name php -m
...type:
docker-compose run --rm container_name php7.0 -m
OR
In the Dockerfile, just before ...
WORKDIR /var/www/html/code
...add:
RUN update-alternatives --set php /usr/bin/php7.0
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.
I would like to install the ext-http extension because I have this error when I execute composer install command in my php-apache container:
The requested PHP extension ext-http * is missing from your system.
Install or enable PHP's http extension.
My Dockerfile:
ARG PHP_VERSION=""
FROM php:${PHP_VERSION}-apache
ENV COMPOSER_ALLOW_SUPERUSER=1
EXPOSE 80
WORKDIR /${PROJECT_DIRECTORY}
# git, unzip & zip are for composer
RUN apt-get update -qq && \
apt-get install -qy \
git \
gnupg \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libicu-dev \
libxml2-dev \
wget \
nano \
unzip \
zip && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# PHP Extensions
RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap
ADD php/php.ini /usr/local/etc/php/conf.d/${PROJECT_DIRECTORY}.ini
# Apache
RUN a2enmod rewrite remoteip
ADD vhosts/vhost.conf /etc/apache2/sites-available/000-default.conf
I have "ext-http": "*" in require node of my composer.json.
I tried:
RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap ext-http
And I have this error:
Step 7/10 : RUN docker-php-ext-install -j$(nproc) opcache pdo_mysql
intl xml soap ext-http ---> Running in 8ef2c127b632 error:
/usr/src/php/ext/ext-http does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name
...] ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see
docker-php-ext-configure
Possible values for ext-name: bcmath bz2 calendar ctype curl dba dom
enchant exif ffi fileinfo filter ftp gd gettext gmp hash iconv imap
intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib
pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql
phar posix pspell readline reflection session shmop simplexml snmp
soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy
tokenizer xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded. ERROR:
Service 'apache' failed to build: The command '/bin/sh -c
docker-php-ext-install -j$(nproc) opcache pdo_mysql intl xml soap
ext-http' returned a non-zero code: 1 Failed to deploy 'Compose:
.docker': docker-compose process finished with exit code 1
How can I install this extension please?
I published a script that lets you install the http PHP extension (and many others) with just these lines:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions http
the script takes care of the PHP version, and installs all the required APT (for Debian) or APK (for Alpine) packages.
More details here: https://github.com/mlocati/docker-php-extension-installer
You might want to install it via pecl. The http extension also has dependencies.
RUN docker-php-ext-install hash iconv \
&& pecl install raphf propro \
&& docker-php-ext-enable raphf propro \
&& pecl install pecl_http \
&& echo -e "extension=raphf.so\nextension=propro.so\nextension=http.so" > /usr/local/etc/php/conf.d/docker-php-ext-http.ini \
&& rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.ini \
&& rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.ini
I've got the inspiration via https://hub.docker.com/r/realpaul/docker-php/dockerfile
I would like to deploy my Laravel project with GitLabCI and docker. I have a yaml file with the following before_script:
docker-php-ext-install mbstring mcrypt pdo_mysql curl json intl gd xml zip bz2 opcache
Its return with this:
error: /usr/src/php/ext/mcrypt does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]
ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see docker-php-ext-configure
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
ERROR: Job failed: exit code 1
I tried to install manually the mcrypt with apt-get install following these answers, but nothing worked for me. Cheked this forum post too, but there is no mentioned about this error.
gitlab-ci.yaml file:
before_script:
# Update packages
- apt-get update -yqq
- apt-get install -my wget gnupg
# Upgrade to Node 7
- curl -sL https://deb.nodesource.com/setup_7.x | bash -
# Install dependencies
- apt-get install bzip2 git nodejs libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq
# Install php extensions
- docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache
# Install Node dependencies.
# comment this out if you don't have a node dependency
- npm install
- npm install -g bower
- npm install -g gulp-cli
# Install Composer and project dependencies.
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install
Using php7.0 and Laravel 5.3.2
I ran into this issue. Mcrypt was deprecated in PHP 7.2. Here's how to get around it now:
image: php:7.2
before_script:
# Update packages
- apt-get update -yqq
# Install dependencies
- apt-get install git libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq
# Install php extensions
- docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache pcntl
....
# PHP 7.2 Mcrypt & pcntl
- pecl install mcrypt-1.0.1
- docker-php-ext-enable mcrypt
....
I try to install mcrypt in my docker image based on php:7.2-apache. Therefore I use the RUN-Command from the documentation and also answerd here but I receive this error:
error: /usr/src/php/ext/mcrypt does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]
ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see docker-php-ext-configure
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zend_test zip
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev && docker-php-ext-install -j$(nproc) iconv mcrypt gd mbstring zip' returned a non-zero code: 1
My Dockerfile:
FROM php:7.2-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt gd mbstring zip
# && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
# && docker-php-ext-install -j$(nproc) gd
COPY ./etc/000-default.conf /etc/apache2/sites-available/
EXPOSE 80
Has anybody an idea how to solve or how to get the needed files in the requested folder?
Thanks!
mcrypt extension is not provided with the PHP source since 7.2 , but are instead available through PECL. To install a PECL extension in docker, use pecl install to download and compile it, then use docker-php-ext-enable to enable it:
pecl install mcrypt-1.0.5
docker-php-ext-enable mcrypt
Before the pecl install you may need to install/update the package libmcrypt-dev
apt-get update && apt-get install -y libmcrypt-dev
Building on MoiioM's answer, this worked for me using the 7.2-stretch Docker image from PHP
RUN apt-get update && apt-get install -y libmcrypt-dev \
&& pecl install mcrypt-1.0.4 \
&& docker-php-ext-enable mcrypt
To install mcrypt extension you have to make sure you did install libmcrypt-dev which is required.
Try to add:
RUN apt install libmcrypt-dev
before you are trying to install extensions for php.
Update
Try to run first:
docker-php-ext-configure mcrypt
and then
docker-php-ext-install mcrypt
I tried to install some needed extensions for php using docker.
Here is my Dockerfile :
FROM php:7-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libsqlite3-dev \
libssl-dev \
libcurl3-dev \
libxml2-dev \
libzzip-dev \
&& docker-php-ext-install iconv json mcrypt mbstring mysql mysqli pdo_mysql pdo_sqlite phar curl ftp hash session simplexml tokenizer xml xmlrpc zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
WORKDIR /var/www
CMD ["php7-fpm"]
And here is the error I got :
error: /usr/src/php/ext/mysql does not exist
usage: /usr/local/bin/docker-php-ext-install [-jN] ext-name [ext-name ...]
ie: /usr/local/bin/docker-php-ext-install gd mysqli
/usr/local/bin/docker-php-ext-install pdo pdo_mysql
/usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
if custom ./configure arguments are necessary, see docker-php-ext-configure
Possible values for ext-name:
bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip
ERROR: Service 'php-localdev' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng12-dev libsqlite3-dev libssl-dev libcurl3-dev libxml2-dev libzzip-dev && /usr/local/bin/docker-php-ext-install iconv json mcrypt mbstring mysql mysqli pdo_mysql pdo_sqlite phar curl ftp hash session simplexml tokenizer xml xmlrpc zip && /usr/local/bin/docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && /usr/local/bin/docker-php-ext-install gd'
returned a non-zero code: 1
Do you see any issues in my Dockerfile, or the problem is elsewhere ?
I was inspired for this Dockerfile by the php docker hub.
Thansk for your help.
In the error output, it lists the possible values for ext_name. mysql isn't listed. There is mysqli and pdo_mysql, but not mysql. Your command does include mysql, and the first line of the error seems to be complaining about that. Try taking that out and see if that works.