Home » Php » Apache, PHP, WordPress caching issue in Docker container

Apache, PHP, WordPress caching issue in Docker container

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m on OS X using the Virtualbox driver for docker. Using the official WordPress docker image, I setup a volume from my local machine to map to the container

/Users/gezimhome/projects/zr/src:/var/www/html/wp-content/plugins/zr

When I update files in the host, they show updated in the container but changes don’t reflect on the website until a few minutes later. I suspect it might be Apache caching something as I don’t have any WordPress caching plugins installed.

Update: I’ve not tried other types of files. The PHP files are not being updated when I load the site in the browser (or even using curl).

Update 2: Here’s the .htaccess file.
Here’s the docker virtualbox info

How to&Answers:

It turns out this was caused by opcache in PHP. Opcache was enabled in the wordpress docker image as follows:

RUN { \
        echo 'opcache.memory_consumption=128'; \
        echo 'opcache.interned_strings_buffer=8'; \
        echo 'opcache.max_accelerated_files=4000'; \
        echo 'opcache.revalidate_freq=60'; \
        echo 'opcache.fast_shutdown=1'; \
        echo 'opcache.enable_cli=1'; \
    } > /usr/local/etc/php/conf.d/opcache-recommended.ini

So, I created a new docker image for wordpress that disables caching. It’s essentially this:

FROM wordpress:latest
RUN rm -rf /usr/local/etc/php/conf.d/opcache-recommended.ini