3

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
4

2 回答 2

1

有安装 php 库的 docker 命令。因此,不要使用 linux 命令,例如:apk add php-tidy usingdocker-php-ext-install tidy解决了我的问题。下面是有效的 docker 文件。

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

于 2019-02-25T17:37:31.830 回答
0

在基于 Debian Bullseye 的 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
于 2021-12-12T21:07:58.930 回答