WordPress Multi-Site on Docker – How to Add Apache mod_headers to Solve CORS Issues and php File Size Limit

I’ve been using a WordPress Docker for some time now. My Docker is invoked through the docker-compose toolset, and it generally functions well. However, at times, specific configurations are needed. For instance, when adjusting the PHP file size limitation or adding mod_headers to address CORS issues on WordPress.

The key is to override the Docker container with your own files when necessary. To handle larger file uploads in WordPress-Apache, without needing to rebuild the container, you must include a file in the container’s /usr/local/etc/php/conf.d/ directory. In my case, this file is named “uploads.ini,” and it contains the following content:

file_uploads = On
memory_limit = 200M
upload_max_filesize = 200M
post_max_size = 200M
max_execution_time = 300

To link this file to Docker, save it in your user’s home directory (or a known predefined location) and add the following flag to the “docker run” command or as part of the mapped volumes in your “docker-compose.yaml” file:

-v ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

This ensures that the file is included in the Docker image without requiring you to maintain a separate copy of the Docker file.

The same approach applies to handling CORS in the WordPress-Apache container. There are two relevant files you need to manage. One is the “.htaccess” file, which must be mapped to the DocumentRoot, and the other is a file that directs Apache to load the “mod_headers” directive.

To handle the CORS issue, your “.htaccess” file should include the following lines:

# Handle fonts and CSS CORS 
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin *

To enable “mod_headers,” you need a file named “header.load” with the following content:

LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so

Both files can be mapped into the container using the following arguments for the “docker run” command:

-v .htaccess:/var/www/html/.htaccess -v headers.load:/etc/apache2/mods-enabled/headers.load

By following these steps, you can effectively handle CORS and allow ‘Elementor’ to load correctly on a multi-site WordPress setup.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.