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/*;
Related
I am trying upgrade this docker file from 7.3 to 7.4 but getting executor failed error.
Detailed error:
executor failed running [/bin/sh -c docker-php-ext-install bcmath
ctype dom gd hash iconv intl mbstring
mysqli opcache pdo_mysql simplexml sockets soap
sodium xsl zip ;]: exit code: 2
FROM php:7.4-fpm as base
ENV COMPOSER_HOME=/tmp/composer
ENV APCU_VERSION=5.1.18
RUN apt-get update && apt-get install -y --no-install-recommends gnupg \
netcat \
sudo \
libicu-dev \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libsodium-dev \
libxml2-dev \
libxslt-dev \
libzip-dev \
rsync \
unzip \
git \
openssh-client \
;
RUN pecl install apcu-${APCU_VERSION}
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install \
bcmath \
ctype \
dom \
gd \
hash \
iconv \
intl \
mbstring \
mysqli \
opcache \
pdo_mysql \
simplexml \
sockets \
soap \
sodium \
xsl \
zip \
;
RUN docker-php-ext-enable apcu
RUN echo "memory_limit=1G" >> /usr/local/etc/php/conf.d/zz-memory-limit-php.ini
RUN echo "apc.enable=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "opcache.memory_consumption=512MB" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.max_accelerated_files=60000" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.consistency_checks=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.validate_timestamps=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-opcache.conf
FROM base as build
RUN curl https://files.magerun.net/n98-magerun2.phar -o /usr/local/bin/magerun \
&& chmod 755 /usr/local/bin/magerun
RUN mkdir -p -m 0775 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN mkdir -p -m 0775 ~/.ssh && ssh-keyscan github.com >> /var/www/.ssh
# USER www-data
WORKDIR /var/www/html
ARG COMPOSER_AUTH
COPY --from=composer:1 /usr/bin/composer /usr/bin/composer
RUN composer global require hirak/prestissimo
COPY auth.json auth.json
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN --mount=type=ssh,id=id_rsa php -d memory_limit=2G $(which composer) install --no-progress --no-dev
COPY app/etc/config.php app/etc/config.php
COPY bin bin
FROM build as app
ENV MAGE_MODE=production
RUN php -d memory_limit=2G bin/magento setup:di:compile
RUN composer dump-autoload --optimize --apcu
RUN php -d memory_limit=2G bin/magento setup:static-content:deploy -f
RUN rm -rf /var/www/html/var/cache
RUN rm -rf /var/www/html/var/page_cache
RUN rm -rf /var/www/html/var/session
COPY --chown=www-data app/etc/env.docker.php app/etc/env.php
i had a similar issue today.
Seems that in php7.4 iconv his a native library.
So you should try to remove it from your Dockerfile and see if it works.
Even if it's an 6 month old issue, i hope it could help someone.
Chears.
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'm not able to enable webp support inside a docker container. ¿What am I missing in Dockerfile configuration?
When execute a php script I get this error:
Fatal error: Uncaught Error: Call to undefined function imagewebp()....
Executing php -i to see if gd is enabled:
root#a5e8fec22e8b:/var/www/html# php -i | grep -ia gd
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled <--------- GD is enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
php gd_info output:
"GD Version":"bundled (2.1.0 compatible)",
"FreeType Support":true,
"FreeType Linkage":"with freetype",
"GIF Read Support":true,
"GIF Create Support":true,
"JPEG Support":true,
"PNG Support":true,"WBMP Support":true,
"XPM Support":false,
"XBM Support":true,
"WebP Support":false, <----------------------------- :?
"BMP Support":true,
"JIS-mapped Japanese Font Support":false
Dockerfile
FROM php:7.2-apache
COPY ./apache2/sites-available/*.conf /etc/apache2/sites-available/
RUN apt-get update && apt-get install --no-install-recommends -y \
wget \
nano \
git \
unzip \
iputils-ping
# Install PHP extensions deps
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libjpeg-dev \
libwebp-dev \
libpng-dev \
libmcrypt-dev \
zlib1g-dev \
libicu-dev \
g++ \
unixodbc-dev \
libxml2-dev \
libaio-dev \
libmemcached-dev \
freetds-dev \
libssl-dev \
openssl \
libsodium-dev
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin \
--filename=composer
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-webp-dir=/usr/include/ \
&& docker-php-ext-configure pdo_dblib --with-libdir=/lib/x86_64-linux-gnu \
&& pecl install sqlsrv-4.1.6.1 \
&& pecl install pdo_sqlsrv-4.1.6.1 \
&& pecl install redis \
&& pecl install memcached \
&& pecl install -f libsodium \
&& docker-php-ext-install \
iconv \
mbstring \
intl \
gd \
mysqli \
pdo_mysql \
pdo_dblib \
soap \
sockets \
sodium \
zip \
pcntl \
ftp \
&& docker-php-ext-enable \
sqlsrv \
pdo_sqlsrv \
redis \
memcached \
opcache \
gd \
sodium
RUN a2enmod rewrite negotiation
RUN mkdir /home/laravel && \
chown -R www-data:www-data /home/laravel
RUN chown -R www-data:www-data /var/www
RUN service apache2 restart
I tested a simple Dockerfile based on an example copied from this repository.
My Dockerfile looks like this:
FROM php:7.2-apache
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
COPY index.php /var/www/html/
Before building, I create a php file, index.php, to copy to my new image.
<?php
phpinfo();
?>
Then, I build and run my new image with these commands:
docker build -t php7-with-gd -f Dockerfile .
docker run -d --rm -p 88:80 --name test-phpgd php7-with-gd
And my output page with the PHP information looks like this.
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 am trying to use wkhtmltopdf in a container with Docker and Symfony.
The installation is done well, but the result is very different from the reality, so I think some libraries must be missing in the system, but I don't know which one.
I've been checking other questions here and in google, but they don't help.
FROM phpdockerio/php71-fpm:latest
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install cron \
php7.1-mysql \
php-redis \
php7.1-bcmath \
php7.1-gd \
php-imagick \
php7.1-intl \
cron \
python \
xz-utils \
libxrender1 \
libfontconfig1 \
zlib1g \
fontconfig \
libfreetype6 \
libx11-6 \
libxext6 \
wkhtmltopdf
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
RUN cd /tmp \
&& curl "https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz" -L -o "wkhtmltopdf.tar.xz" \
&& tar Jxvf wkhtmltopdf.tar.xz \
&& rm wkhtmltopdf.tar.xz \
&& mv wkhtmltox/include/* /usr/local/include/ \
&& mv wkhtmltox/lib/* /usr/local/lib/ \
&& mv wkhtmltox/bin/* /usr/local/bin/ \
&& mv wkhtmltox/share/* /usr/local/share/
RUN apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
CMD php-fpm -F
This is the result in the container(docker)
And this is the result on my machine (without docker), as it should be.
Any idea what might be happening?