Php can't find tidy - php

I am using a php7 in docker container to run a service based on phpdocx library. It needs tidy and some other extensions installed and active to work. I have installed php-tidy however I am getting following warning.
PHP Warning: PHP Startup: Unable to load dynamic library 'tidy' (tried: /usr/lib/php7/modules/tidy (Error loading shared library /usr/lib/php7/modules/tidy: No such file or directory), /usr/lib/php7/modules/tidy.so (Error relocating /usr/lib/php7/modules/tidy.so: _zval_ptr_dtor: symbol not found)) in Unknown on line 0
Dockerfile
FROM php:7.3.2-cli-alpine3.9
USER root
COPY . code
WORKDIR code
RUN apk update && apk add php-tidy && apk add php-zip && apk add php-curl && apk add php-sodium
# RUN sed -i s/;extension=tidy/extension=tidy/ -f /usr/local/etc/php/php.ini-development
# RUN sed -i s/;extension=tidy/extension=tidy/ -f /usr/local/etc/php/php.ini-production
COPY php.ini /usr/local/etc/php/php.ini-development
COPY php.ini /usr/local/etc/php/php.ini-production
COPY php.ini /usr/local/etc/php/php.ini
CMD php -S 0.0.0.0:8080
Output from docker shell
on running phpinfo()
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => /usr/local/etc/php/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/conf.d
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
# vi /usr/local/etc/php/php.ini
extension=tidy
[Tidy]
; The path to a default tidy configuration file to use when using tidy
; http://php.net/tidy.default-config
;tidy.default_config = /usr/local/lib/php/default.tcfg
; Should tidy clean and repair output automatically?
; WARNING: Do not use this option if you are generating non-html content
; such as dynamic images
; http://php.net/tidy.clean-output
tidy.clean_output = Off
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "/usr/lib/php7/modules/"
; On windows:
;extension_dir = "ext"
#ls /usr/lib/php7/modules/
curl.so sodium.so tidy.so zip.so

There are docker commands to install php libraries. So instead of using linux command eg: apk add php-tidy using docker-php-ext-install tidy solved my problem. Below is the docker file that works.
FROM php:7
ENV DEBIAN_FRONTEND noninteractive
USER root
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y apt-utils
RUN apt-get install -y libzip-dev
RUN apt-get install -y libtidy-dev
RUN apt-get install -y curl
RUN apt-get install -y libcurl3
RUN apt-get install -y libcurl3-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-install curl
RUN docker-php-ext-install tidy
RUN docker-php-ext-enable zip
RUN docker-php-ext-enable curl
RUN docker-php-ext-enable tidy
COPY . code
WORKDIR code
EXPOSE 8080
CMD php -S 0.0.0.0:8080

On Debian Bullseye based Dockerfile:
RUN apt-get update && \
apt-get install -y libtidy-dev && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-install tidy && \
docker-php-ext-enable tidy

Related

Docker container takes 8 seconds to execute simple php comand in windows

I was using a docker container with php:8.1.6-cli and running my laravel aplication.
When i attach the terminal to the container and run a simple command php artisan inspire the docker takes 8 seconds to execute.
My php.ini config:
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Sao_Paulo
My Dockerfile for this container:
FROM php:8.1.6-cli
LABEL maintainer="Crazynds"
WORKDIR /workspace
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC-3
ENV NODE_VERSION=16
USER root
RUN apt-get update \
&& apt-get install -y libcurl4-openssl-dev libonig-dev libzip-dev libpq-dev build-essential gnupg gosu curl zip unzip git supervisor libcap2-bin libpng-dev python2 locales \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -
RUN apt-get install -y nodejs nano wget dos2unix
RUN apt-get -y autoremove \
&& apt-get clean\
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pecl install redis && docker-php-ext-enable redis; exit 0
RUN docker-php-ext-install pdo_mysql pdo_pgsql mbstring exif pcntl curl zip gd
ENTRYPOINT ["sleep","infinity"]
How i find the problem that takes most of the time to execute the php comands?
Is there any way to check what is consuming each part of time in the execution?
I find the solution. The docker with volumes mounted using Windows dirs are slow.
The solution for my problem is to create the vendor folder and the node_modules in separated volumes, instead of mounting them from Windows folder.
That alone gave a big performance boost, now the response time is around 1 second, but if I mounted my entire project on the volume instead of a folder, it would be much faster.

GD installed in docker but imagecreatetruecolor doesn't exist

Another issue with docker, i have installed php gd and i can see it in phpinfo yet when i try to use imagecreatetruecolor it doesn't seem to exist.
I am building dockerfile like this:
FROM php:7.4-fpm
RUN apt update
RUN apt-get install -y libzip-dev zip curl libpng-dev
RUN docker-php-ext-install mysqli pdo pdo_mysql zip gd mbstring
RUN docker-php-ext-enable pdo_mysql zip gd
RUN apt -y install bash
RUN apt -y install procps
RUN apt -y install iputils-ping
RUN apt -y install vim
# make sure www-data has correct uid and gid
RUN usermod --uid 1001 www-data
RUN groupmod --gid 1001 www-data
COPY ./docker/php-backend/php.ini /usr/local/etc/php/conf.d/docker-php.ini
RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
RUN php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN rm -f composer-setup.php
WORKDIR /usr/share/nginx/html
RUN mkdir bin && mkdir config && mkdir public && mkdir src && mkdir templates && mkdir var && mkdir var/log && mkdir var/cache
COPY ./api/bin/ ./bin/
COPY ./api/config/ ./config/
COPY ./api/public/ ./public/
COPY ./api/src/ ./src/
COPY ./api/templates/ ./templates/
COPY ./api/composer.json .
COPY ./api/composer.lock .
COPY ./api/symfony.lock .
RUN composer install
RUN rm composer.json composer.lock symfony.lock
RUN rm /usr/local/bin/composer
phpinfo:
GD Support enabled GD Version bundled (2.1.0 compatible) GIF Read
Support enabled GIF Create Support enabled PNG Support enabled libPNG
Version 1.6.37 WBMP Support enabled XBM Support enabled BMP
Support enabled TGA Read Support enabled
I'm simply running an if to check if the function exists
// check to see if GD function exist
if(!function_exists('imagecreatetruecolor')) {
$error = "GD Library Error: imagecreatetruecolor does not exist";
die( $error );
}

Docker fails to enable php extensions

I am trying to install some php extensions all day but an error I do not understand occurs. Basically if I remove the install docker-php-ext-enable line everything seems to work normally (except my app that depends on them).
Dockerfile
FROM php:8.0-apache
RUN apt-get update && \
apt-get install -y unzip libcurl4-openssl-dev zlib1g-dev libpng-dev libxml2-dev libzip-dev
RUN a2enmod rewrite
RUN docker-php-ext-enable bcmath gd mysqli soap zip xml ctype curl fileinfo json
COPY idoit-1.16.2.zip /temp/idoit-1.16.2.zip
RUN unzip /temp/idoit-1.16.2.zip -d /var/www
RUN rm /temp/idoit-1.16.2.zip
COPY apache-vhost.conf /etc/apache2/sites-available/000-default.conf
# RUN chown -R www-data:www-data /var/www
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
EXPOSE 80
Here is what I get when i run sudo docker build -t test .
Sending build context to Docker daemon 153.9MB
Step 1/23 : FROM php:8.0-apache
---> 1157b188bd87
Step 2/23 : RUN apt-get update && apt-get install -y unzip libcurl4-openssl-dev zlib1g-dev libpng-dev libxml2-dev libzip-dev
---> Using cache
---> aacd74715e3f
Step 3/23 : RUN a2enmod rewrite
---> Using cache
---> 1ab1cd3d1228
Step 4/23 : RUN docker-php-ext-enable fileinfo
---> Running in 7d8a84075a50
error: 'fileinfo' does not exist
usage: /usr/local/bin/docker-php-ext-enable [options] module-name [module-name ...]
ie: /usr/local/bin/docker-php-ext-enable gd mysqli
/usr/local/bin/docker-php-ext-enable pdo pdo_mysql
/usr/local/bin/docker-php-ext-enable --ini-name 0-apc.ini apcu apc
Possible values for module-name:
opcache.so sodium.so
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
Any ideas?

Can't build php docker image [duplicate]

This question already has answers here:
ADD failed : No such file/Directory while building docker image
(3 answers)
Closed 2 years ago.
I got this error when building docker php image
Step 13/25 : ADD php.ini /usr/local/etc/php/php.ini
ERROR: Service 'phpt3' failed to build: ADD failed: stat
/var/lib/docker/tmp/docker-builder310748204/php.ini: no
such file or directory
Below is the docker file:
FROM php:7.3-fpm
# install the PHP extensions we need
RUN apt-get update \
&& apt-get install -y --no-install-recommends msmtp mailutils vim curl debconf subversion git apt-transport-https apt-utils \
build-essential locales acl mailutils wget nodejs \
gnupg gnupg1 gnupg2 \
zlib1g-dev zlib1g-dev libicu-dev g++ \
sudo
# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
# MYSQLI
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Install ext-zip
RUN apt-get install -y unzip libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo_mysql json calendar intl
ADD php.ini /usr/local/etc/php/php.ini
COPY additionnal.ini /usr/local/etc/php/conf.d/
COPY php-fpm-pool.conf /usr/local/etc/php/pool.d/www.conf
RUN rm -rf /var/lib/apt/lists/* \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# set up sendmail config, see http://linux.die.net/man/5/ssmtp.conf for options
RUN echo "hostname=localhost.localdomain" > /etc/msmtp/msmtp.conf
RUN echo "mailhub=maildevt3" >> /etc/msmtp/msmtp.conf
# The above 'maildevt3' is the name you used for the link command
# in your docker-compose file or docker link command.
# Docker automatically adds that name in the hosts file
# of the container you're linking MailDev to.
# Set up php sendmail config
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
# Fully qualified domain name configuration for sendmail on localhost.
# Without this sendmail will not work.
# This must match the value for 'hostname' field that you set in ssmtp.conf.
RUN echo "localhost localhost.localdomain" >> /etc/hosts
WORKDIR /var/www/
EXPOSE 9000
CMD ["php-fpm"]
Can anyone help me to overcome this bug.
I'm doing this tutorial
https://passions.miary.dev/2019/08/30/docker-maildev-fr/
It looks like the image installer does not have the rights to write to the installation directory.
-> How to fix:
ADD failed : No such file/Directory while building docker image
If that doesn't work: test if the folder, which is shown in the error exists.
Give enough permissions to the directory with chmod -> https://wiki.ubuntuusers.de/chmod/

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