Skip to content

Instantly share code, notes, and snippets.

@andrewscaya
Forked from weierophinney/Dockerfile
Created November 2, 2018 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewscaya/268bc3c26c2be95a4045ced025f621fb to your computer and use it in GitHub Desktop.
Save andrewscaya/268bc3c26c2be95a4045ced025f621fb to your computer and use it in GitHub Desktop.
Getting ext-tidy to work on alpine-based PHP images

The problem I ran into is that the libtidy that ext-tidy compiles against on recent (3.7+) Alpine distributions is 5.6.0, while Debian-based distributions use libtidy 5.2.0. When applications using ext-tidy run against libtidy 5.6.0, they produce content that libxml2 cannot deal with (e.g., when using DOMDocument::loadXML()), whereas the earlier versions work fine.

As such, I needed to find a way to:

  • Install libtidy 5.2.0
  • Compile ext-tidy against it
# DOCKER-VERSION 1.3.2
FROM php:7.2-cli-alpine3.8
# Compile-time dependencies
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories
RUN apk update && \
apk add --no-cache 'tidyhtml-dev==5.2.0-r1'
# Install the extension
RUN docker-php-ext-install -j$(nproc) tidy
@andrewscaya
Copy link
Author

FOR FUTURE REFERENCE

Would compiling from source be a viable solution for you?

If so, the modified Dockerfile would look something like this:


# DOCKER-VERSION        1.3.2

FROM php:7.2-cli-alpine3.8

# Compile-time dependencies
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories
RUN apk update && \
  apk add gcc g++ make cmake git
RUN cd && \
  git clone https://github.com/htacg/tidy-html5.git && \
  cd tidy-html5 && \
  git checkout 5.2.0 && \
  cd build/cmake/ && \
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_TAB2SPACE=ON \
  ../.. && \
  make && \
  make install && \
  install -v -m755 tab2space /usr/bin && \
  cd && \
  rm -rf tidy-html5

# Install the extension
RUN docker-php-ext-install -j$(nproc) tidy

I've pushed my test build to my Docker Hub: 'docker pull andrewscaya/test_php7211-tidy520'. You can pull the image and see if this is enough to "fix" the issue for now.

If I can be of any further help, please let me know. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment