Skip to content

Instantly share code, notes, and snippets.

@kingkool68
Last active September 27, 2023 16:40
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 kingkool68/a8edda015cce75fce9b141a12c3f39ff to your computer and use it in GitHub Desktop.
Save kingkool68/a8edda015cce75fce9b141a12c3f39ff to your computer and use it in GitHub Desktop.
Compiling Photon OpenCV PHP extension via Docker

Compile the Photon OpenCV PHP extension via Docker.

You can build the Docker container yourself by running: docker build -t photon-docker .

FROM php:8.1-apache
RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends \
vim \
git \
subversion \
libopencv-dev \
libwebp-dev \
libgif-dev \
libwebpdemux2 \
libwebpmux3 \
# libexiv2-dev \
libheif-dev \
liblcms2-dev
# Download and compile Exiv2 0.28 since the Ubuntu package is behind
RUN apt-get install --yes build-essential git clang ccache python3 libxml2-utils cmake python3 libexpat1-dev libz-dev zlib1g-dev libbrotli-dev libssh-dev libcurl4-openssl-dev libgtest-dev google-mock libinih-dev
RUN git clone --depth 1 --branch v0.28.0 https://github.com/Exiv2/exiv2 /tmp/exiv2
RUN mkdir /tmp/exiv2/build
RUN cd /tmp/exiv2/build && cmake .. -G "Unix Makefiles" && make && make install
# Download and Compile PHP-CPP from https://github.com/fast-debug/PHP-CPP
RUN svn co --quiet --trust-server-cert --non-interactive https://github.com/fast-debug/PHP-CPP /tmp/php-cpp
RUN cd /tmp/php-cpp/trunk && make && make install
## Download and compile Photon OpenCV
RUN git clone --depth 1 https://github.com/Automattic/photon-opencv/ /tmp/photon-opencv
RUN cd /tmp/photon-opencv && make && make install
RUN docker-php-ext-enable photon-opencv
RUN { \
echo '<Directory /var/www/html>'; \
echo ' RewriteEngine on'; \
echo ' RewriteCond %{REQUEST_FILENAME} !-f'; \
echo ' RewriteRule .* /index.php [L,QSA]'; \
echo '</Directory>'; \
} >> /etc/apache2/conf-available/photon.conf
RUN a2enmod rewrite
RUN a2enconf photon
RUN svn co --quiet --trust-server-cert --non-interactive https://code.svn.wordpress.org/photon /var/www/html
# Remove filter_var check that prevents connecting to local IP addresses (photon r436).
RUN sed -i.bak -e 's/ *FILTER_FLAG_NO_PRIV_RANGE *|//g' /var/www/html/index.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment