Dockerfile for latest WordPress and Latest PHP

I am using Docker to run WordPress. Official image doesn’t contain imagick as well as tidy. These two are necessary extensions for cache plugins and image manipulations including resize and compression to work.

Follwing Dockerfile will have latest PHP as well as WordPress. As long as you are at PHP7.4.X as well as wordpress 5.4.X we are good to go.

Dockerfile

FROM wordpress:5.4.2-php7.4-apache
# Better WordPress Health-Check
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
#RUN printf "\n" | pecl install imagick
RUN docker-php-ext-enable imagick
RUN docker-php-ext-install bcmath exif
# W3Cache tweaks
RUN apt-get update && apt-get install -y tidy libtidy-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN a2enmod headers ext_filter 

RUN set -eux; \
	a2enmod rewrite expires; \
	\
# https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html
	a2enmod remoteip; \
	{ \
		echo 'RemoteIPHeader X-Forwarded-For'; \
# these IP ranges are reserved for "private" use and should thus *usually* be safe inside Docker
		echo 'RemoteIPTrustedProxy 172.27.0.1/28'; \
	} > /etc/apache2/conf-available/remoteip.conf; \
	a2enconf remoteip; \
# https://github.com/docker-library/wordpress/issues/383#issuecomment-507886512
# (replace all instances of "%h" with "%a" in LogFormat)
	find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +

RUN docker-php-ext-install tidy
spacebox-wordpess-dockerfile

Worth Sharing?

6 Comments

    1. It doesn’t otherwise kubernetes and all would have been not out there. In fact, many hosting companies are relying on dockers these days.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>