Following my previous post.
I managed to install oci8-2.2.0 via pecl.
Now I have a problem, I cannot launch the commands:
docker-php-ext- *
It always gives me an error:
/ bin / sh: 1: docker-php-ext-configure: not found
In my Dockerfile :
FROM ubuntu:latest
COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker
COPY --from=docker/compose:latest /usr/local/bin/docker-compose /usr/bin/docker-compose
I install my necessary packages:
RUN apt-get install -y \
apache2 \
libapache2-mod-php \
libldap2-dev \
vim \
curl \
git \
openssl \
bash \
mysql-client \
g++ \
gcc \
make \
libaio1 \
wget \
unzip \
libapache2-mod-php7.4 \
software-properties-common \
systemtap-sdt-dev \
build-essential \
libcurl4-gnutls-dev \
unixodbc-dev \
net-tools
I install the PHP dependencies:
RUN apt-add-repository -y ppa:ondrej/php
RUN apt-get update
RUN apt-get install -y \
php7.4 \
php7.4-fpm \
php7.4-xml \
php-common \
php7.4-gd \
php7.4-mbstring \
php7.4-gd \
php7.4-iconv \
php7.4-pdo \
php7.4-tokenizer \
php7.4-mysql \
php-ldap \
php7.4-ldap \
php7.4-fileinfo \
php7.4-simplexml \
php7.4-xmlwriter \
php7.4-zip \
php7.4-json \
php-dev \
php-pear
Finally, the commands are launched after installing Oracle Instant Client:
# Oracle instantclient
RUN export PHP_DTRACE=yes
ADD instantclient-basic-linux.x64-12.2.0.1.0.zip /tmp/
ADD instantclient-sdk-linux.x64-12.2.0.1.0.zip /tmp/
RUN unzip /tmp/instantclient-basic-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN unzip /tmp/instantclient-sdk-linux.x64-12.2.0.1.0.zip -d /usr/local/
RUN mv /usr/local/instantclient_12_2 /usr/local/instantclient
RUN ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so
RUN ln -s /usr/local/instantclient/libocci.so.12.1 /usr/local/instantclient/libocci.so
ENV LD_LIBRARY_PATH=/usr/local/instantclient
RUN echo "instantclient,/usr/local/instantclient"| pecl install oci8-2.2.0
RUN docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/usr/local/instantclient
RUN docker-php-ext-install pdo_oci
RUN docker-php-ext-enable oci8-2.2.0
Any idea for Docker to find docker-php-ext- commands?
BR
Commands docker-php-ext- * are helper scripts provided by PHP images. But you are using ubuntu:latest image, which is doesn't contain them.
You can use scripts from php image for example that one. But I think it is easier to use php docker images.
I've build the Saxon/C PHP extension in a PHP-FPM docker image. The current extension name is ext-saxon/c, while PhpStorm and composer expect the extension name to be ext-saxonc. Is it possible to change/override that in either the Saxon build process or in PhpStorm?
When I use the code in PhpStorm, I get the following error:
To make PhpStorm aware of the Saxon extension, I have to manually enable it in the PHP Runtime settings, because it is not recognized automatically by the interpreter:
But now, I get the message that the ext-saxonc PHP extension is missing from my composer.json file.
In my composer.json file, I can do the following:
"require": {
"ext-saxon/c": "*",
}
But I cannot do the below, because that extension is not recognized as installed.
"require": {
"ext-saxonc": "*",
}
My docker code to build the extension:
FROM php:7.4.5-fpm
ARG saxon='libsaxon-HEC-setup64-v1.2.1'
RUN set -eux; \
apt-get update && apt-get install -y --no-install-recommends wget; \
cd /tmp && wget --quiet https://www.saxonica.com/saxon-c/${saxon}.zip; \
unzip ${saxon}.zip; \
./${saxon} -batch -dest /tmp/saxon; \
cp /tmp/saxon/libsaxonhec.so /usr/lib/; \
cp -r /tmp/saxon/rt /usr/lib; \
ldconfig; \
cd /tmp/saxon/Saxon.C.API/; \
phpize; \
./configure --enable-saxon; \
make -j$(nproc); \
make install; \
docker-php-ext-enable saxon; \
rm -rf /tmp/${saxon} /tmp/${saxon}.zip /tmp/saxon /var/lib/apt/lists/*;
Change line 147 of Saxon.C.API\php_saxon.h (or possibly Saxon.C.API\php5_saxon.h for PHP5) from:
#define PHP_SAXON_EXTNAME "Saxon/C"
to
#define PHP_SAXON_EXTNAME "SaxonC"
using
sed -i 's/#define PHP_SAXON_EXTNAME "Saxon\/C"/#define PHP_SAXON_EXTNAME "SaxonC"/g' php_saxon.h; \
New docker code:
FROM php:7.4.5-fpm
ARG saxon='libsaxon-HEC-setup64-v1.2.1'
RUN set -eux; \
apt-get update && apt-get install -y --no-install-recommends wget; \
cd /tmp && wget --quiet https://www.saxonica.com/saxon-c/${saxon}.zip; \
unzip ${saxon}.zip; \
./${saxon} -batch -dest /tmp/saxon; \
cp /tmp/saxon/libsaxonhec.so /usr/lib/; \
cp -r /tmp/saxon/rt /usr/lib; \
ldconfig; \
cd /tmp/saxon/Saxon.C.API/; \
sed -i 's/#define PHP_SAXON_EXTNAME "Saxon\/C"/#define PHP_SAXON_EXTNAME "saxonc"/g' php_saxon.h; \
phpize; \
./configure --enable-saxon; \
make -j$(nproc); \
make install; \
docker-php-ext-enable saxon; \
rm -rf /tmp/${saxon} /tmp/${saxon}.zip /tmp/saxon /var/lib/apt/lists/*;
I'm trying to install PHP Composer via Docker to be able to run composer as if it was installed on my host (MacOS) locally.
FROM php:7.2.13-apache
# install supporting packages
RUN apt-get update && apt-get install -y --fix-missing \
xz-utils \
build-essential \
pkg-config \
git-core \
autoconf \
libjpeg62-turbo-dev \
libsodium-dev \
libpng-dev \
libcurl4-openssl-dev \
libpq-dev \
libpspell-dev \
libsqlite3-dev \
libmagickwand-dev \
libzip-dev \
imagemagick \
subversion \
python \
g++ \
curl \
vim \
wget \
netcat \
chrpath
# install officially supported php extensions
RUN docker-php-ext-install \
iconv \
sodium \
opcache \
curl \
gd \
mysqli \
exif \
mbstring \
pdo \
pdo_pgsql \
pdo_mysql \
pdo_sqlite \
pspell \
pgsql \
soap \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
# PECL modules
RUN pecl install imagick \
&& pecl install xdebug-2.6.0
COPY ./xdebug/xdebug.ini /usr/local/etc/php/conf.d/
# Enable PECL modules
RUN docker-php-ext-enable imagick xdebug
# cleanup apt
RUN apt-get clean
RUN apt-get autoremove -y
# enable apache modules
RUN a2enmod rewrite headers cache cache_disk expires vhost_alias userdir autoindex
RUN service apache2 restart
RUN service apache-htcacheclean start
RUN usermod -u 1000 www-data
RUN usermod -G staff www-data
RUN chown -R www-data:www-data /var/www
RUN echo "memory_limit=-1" > "$PHP_INI_DIR/conf.d/memory-limit.ini" \
&& echo "date.timezone=${PHP_TIMEZONE:-UTC}" > "$PHP_INI_DIR/conf.d/date_timezone.ini"
RUN apk add --no-cache --virtual .build-deps zlib-dev libzip-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .composer-phpext-rundeps $runDeps \
&& apk del .build-deps
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
ENV COMPOSER_VERSION 1.8.0
RUN curl --silent --fail --location --retry 3 --output /tmp/installer.php --url https://raw.githubusercontent.com/composer/getcomposer.org/b107d959a5924af895807021fcef4ffec5a76aa9/web/installer \
&& php -r " \
\$signature = '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061'; \
\$hash = hash('SHA384', file_get_contents('/tmp/installer.php')); \
if (!hash_equals(\$signature, \$hash)) { \
unlink('/tmp/installer.php'); \
echo 'Integrity check failed, installer is either corrupt or worse.' . PHP_EOL; \
exit(1); \
}" \
&& php /tmp/installer.php --no-ansi --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION} \
&& composer --ansi --version --no-interaction \
&& rm -rf /tmp/* /tmp/.htaccess
RUN chmod 700 /usr/bin/composer
COPY docker-entrypoint.sh /docker-entrypoint.sh
WORKDIR /var/www
CMD ["apache2-foreground"]
EXPOSE 80
docker-entrypoint.sh has the following code (from official composer docker page):
#!/usr/bin/env bash
isCommand() {
for cmd in \
"about" \
"archive" \
"browse" \
"check-platform-reqs" \
"clear-cache" \
"clearcache" \
"config" \
"create-project" \
"depends" \
"diagnose" \
"dump-autoload" \
"dumpautoload" \
"exec" \
"global" \
"help" \
"home" \
"info" \
"init" \
"install" \
"licenses" \
"list" \
"outdated" \
"prohibits" \
"remove" \
"require" \
"run-script" \
"search" \
"self-update" \
"selfupdate" \
"show" \
"status" \
"suggests" \
"update" \
"upgrade" \
"validate" \
"why" \
"why-not"
do
if [ -z "${cmd#"$1"}" ]; then
return 0
fi
done
return 1
}
# check if the first argument passed in looks like a flag
if [ "$(printf %c "$1")" = '-' ]; then
set -- /sbin/tini -- composer "$#"
# check if the first argument passed in is composer
elif [ "$1" = 'composer' ]; then
set -- /sbin/tini -- "$#"
# check if the first argument passed in matches a known command
elif isCommand "$1"; then
set -- /sbin/tini -- composer "$#"
fi
exec "$#"
docker-compose.yml has the following code:
version: '3'
services:
php:
container_name: local_php
build: .
image: php:7.2.13-apache
ports:
- "80:80"
- "443:443"
- "9001:9001"
volumes:
- ../:/var/www/html/
I expect to be able to run composer commands from the terminal (e.g. composer install) but I get the error -bash: composer: command not found each time I try to run any composer command after doing a Dockerfile build.
I finally figured it out; in case someone's trying to achieve the same you got two options basically:
Access php container bash (by using docker exec -it <container name> /bin/bash and navigate to the folder you wish to use composer on, and run composer commands. It might also be helpful to note that docker-compose run <container name> ls would show container's mounted volumes (if you wish to check / make sure).
Run the following commands in macos terminal, to be able to use composer as if it was installed locally:
#!/bin/bash
mkdir ~/.functions
echo '#!/bin/bash
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--workdir /var/www/html/${PWD##*/} \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/var/www/html/${PWD##*/} \
composer "$#"' > ~/.functions/composer
echo 'alias composer="sh ~/.functions/composer"' >> ~/.bash_profile
source ~/.bash_profile
Then in terminal try composer version to see if it's working; if not, try executing source ~/.bash_profile once more, and re-try.
Hope that helps!
I have an symfony application, and i want to create docker container, that contains all needed files. The purpose is to spin up/down containers for scaling, without any other deploying processes. Just with given DB connection.
Building means, pretty much just git clone and running composer install, but some of symfony's post install scripts fail without configured DB.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Can i not run these scripts when i'm building container? Or what the proper way to do symfony deployment?
Using Symfony 3.2, Doctrine2, PHP 7.1
The proper way to build a container without running the db script is by not running there scripts in the build,
Here is the one we use in production for api-platform:
FROM php:7.1-fpm-alpine
RUN apk add --no-cache --virtual .persistent-deps \
git \
icu-libs \
zlib \
postgresql-client
ENV APCU_VERSION 5.1.8
RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
zlib-dev \
postgresql-dev \
sqlite-dev \
pcre-dev \
&& docker-php-ext-install \
intl \
mbstring \
pdo_mysql \
pdo_pgsql \
pdo \
pgsql \
zip \
pdo_sqlite \
&& pecl install \
apcu-${APCU_VERSION} \
&& docker-php-ext-enable --ini-name 20-apcu.ini apcu \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
&& apk del .build-deps
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer
RUN chmod +x /usr/local/bin/docker-app-install-composer
RUN set -xe \
&& apk add --no-cache --virtual .fetch-deps \
openssl \
&& docker-app-install-composer \
&& mv composer.phar /usr/local/bin/composer \
&& apk del .fetch-deps
ARG SYMFONY_ENV=dev
ENV SYMFONY_ENV=dev
RUN if [ "$SYMFONY_ENV" -ne "dev" ]; then \
sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_autostart=0' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_port=9001' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_log=/var/log/xdebug_remote.log' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
pecl install \
xdebug \
&& docker-php-ext-enable xdebug; \
fi;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1
WORKDIR /srv/quotatis
COPY composer.json ./
COPY composer.lock ./
RUN mkdir -p \
var/cache \
var/logs \
var/sessions \
&& composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest -o -a \
&& composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest \
&& composer clear-cache \
# Permissions hack because setfacl does not work on Mac and Windows
&& chown -R www-data var
COPY app app/
COPY bin bin/
COPY src src/
COPY web web/
COPY etc etc/
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
COPY docker/php/start.sh /usr/local/bin/docker-app-start
RUN chmod +x /usr/local/bin/docker-app-start
CMD ["docker-app-start"]
You could see the whole stack (nginx + fpm + varnish on github)
The line that you need in here is this one
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest
I want to build my PHP-FPM image with php-redis extension based on the official PHP Docker image, for example, using this Dockerfile: php:5.6-fpm.
The docs say that I can install extensions this way, installing dependencies for extensions manually:
FROM php:5.6-fpm
# Install modules (iconv, mcrypt and gd extensions)
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
CMD ["php-fpm"]
Without Docker, I installed it with apt-get install php5-redis. But how can I install it using the approach above?
Redis is not an extension that is included in “php-src”, therefore you cannot use docker-php-ext-install. Use PECL:
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
On alpine php 7.3.5 we can use:
RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \
&& pecl install redis \
&& docker-php-ext-enable redis.so
My opinion, the easiest way is:
RUN pecl install redis && docker-php-ext-enable redis
;)
Slightly revised version of starikovs and skyred answers for the current PHP 7 version of the docker image (tested on php:7.0.8-fpm-alpine and php:7.0.8-alpine).
Uses the newly released 3.0 version (June 2016) for PHP 7.
ENV PHPREDIS_VERSION 3.0.0
RUN mkdir -p /usr/src/php/ext/redis \
&& curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
&& echo 'redis' >> /usr/src/php-available-exts \
&& docker-php-ext-install redis
I've found two ways to install php-redis extension for official php-fpm Docker image. Here they are:
The first way is to compile redis from sources and install.
RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/2.2.7.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mv phpredis-2.2.7 /usr/src/php/ext/redis \
&& docker-php-ext-install redis
docker-php-ext-install script is included in php-fpm image and can compile extensions and install them.
The second way you can do it is with PECL.
As TimWolla answered, you can do it with PECL, but in my case, PECL isn't installed by default.
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini
Based on #starikovs answer. I added a variable for docker style.
# install phpredis extension
ENV PHPREDIS_VERSION 2.2.7
RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
&& docker-php-ext-install redis
If you want to use redis as session handler;
RUN { \
echo 'session.save_handler = redis'; \
echo 'session.save_path = tcp://redis:6379'; \
} >> /usr/local/etc/php/conf.d/docker-php-ext-redis.ini
If you want to use redis extension with PHP 7 in 2015 (borrowed from skyred's answer);
ENV PHPREDIS_VERSION php7
RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
&& docker-php-ext-install redis
This works for alpine images:
RUN set -xe \
&& apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS \
&& pecl install -o -f redis \
&& echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini \
&& rm -rf /usr/share/php \
&& rm -rf /tmp/* \
&& apk del .phpize-deps
Edit: Added missing backslash
Tried few ways. On alpine php 7.3.5 we can use:
RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \
&& pecl install redis \
&& docker-php-ext-enable redis.so
I'm using combination of PECL and PHP official docker extension script
RUN pecl bundle -d /usr/src/php/ext redis \
&& rm /usr/src/php/ext/redis-*.tgz \
&& docker-php-ext-install redis
For PHP7 you need to wait for official redis pecl release or use git:
RUN apt-get update \
&& apt-get install git -y -q \
&& git clone -b php7 https://github.com/phpredis/phpredis.git /usr/src/php/ext/redis \
&& docker-php-ext-install redis
Slightly revised version of starikovs and skyred answers for current version of the docker image.
Tested on php:5-fpm-alpine
# install phpredis extension
ENV PHPREDIS_VERSION 2.2.8
ADD https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz /tmp/redis.tar.gz
RUN tar xzf /tmp/redis.tar.gz -C /tmp \
&& mkdir -p /usr/src/php/ext \
&& mv /tmp/phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
&& echo 'redis' >> /usr/src/php-available-exts \
&& docker-php-ext-install redis \
&& rm -rf /usr/src/php/ext/redis
In your Dockerfile you can clone the repo and install it with:
RUN git clone https://github.com/phpredis/phpredis.git /tmp/phpredis \
&& cd /tmp/phpredis \
&& git checkout -b 3.1.2 \ ## or the release you need #
&& phpize \
&& ./configure \
&& make \
&& make install
For image php:7.2-fpm-alpine.
RUN apk add autoconf gcc g++ make && pecl install redis && docker-php-ext-enable redis
You may need to update before
apk --update upgrade