PHP找不到整洁的东西

时间:2019-02-22 09:26:42

标签: php docker alpine tidy phpdocx

我正在php7中使用docker container来运行基于phpdocx库的服务。它需要tidy和已安装并处于活动状态的其他一些扩展。我已经安装了php-tidy,但收到以下警告。

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

docker shell的输出

在运行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

1 个答案:

答案 0 :(得分:1)

有用于安装php库的docker命令。因此,代替使用linux命令,例如:apk add php-tidy使用docker-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