Using open source Minio and the Flysystem S3 module to handle Drupal files

Boxes of old iron

We are in the process of transforming the way we host our applications to a docker based workflow. One of the challenges we face is the file storage. At the heart of our business are open source technologies and tools, therefore  we have looked into in using Minio (more or less the same as Amazon S3 for file storage) instead of local filesystem (or Amazon S3).

We are going to use the Drupal module Flysystem S3 - that works both with Amazon S3 and Minio (compatible with the Amazon S3).

Flysystem is a filesystem abstraction library for PHP which allows you to easily swap out a local filesystem for a remote one - or from one remote to another.

For a new site it is pretty straight forward, for a legacy site you need to migrate your files from one storage to another - that I am going to look into in the next blog post.

Minio container

First we need Minio up and running. For that i am using docker, here is an example docker-compose.yml:

  1. services:
  2. minio:
  3. image: minio/minio:edge
  4. container_name: minio
  5. hostname: minio
  6. ports:
  7. - "8001:9000"
  8. volumes:
  9. - "./data:/data"
  10. environment:
  12. - "MINIO_SECRET_KEY=klertyuiopgrtasjukli"
  13. - "MINIO_REGION=us-east-1"
  14. command: server /data


When you have installed the Flysystem S3 module (and the dependency - the module Flysystem), we need to add the settings for Minio to our settings.php file (there is no settings for this in Drupal. Yet.):

  1. $schemes = [
  2. 's3' => [
  3. 'driver' => 's3',
  4. 'config' => [
  5. 'key' => 'AFGEG578KL',
  6. 'secret' => 'klertyuiopgrtasjukli',
  7. 'region' => 'us-east-1',
  8. 'bucket' => 'my-site',
  9. 'endpoint' => "",
  10. 'protocol' => "http",
  11. 'cname_is_bucket' => false,
  12. "cname" => "",
  13. 'use_path_style_endpoint' => TRUE,
  14. 'public' => true,
  15. 'prefix' => 'publicfiles',
  16. ],
  17. 'cache' => TRUE,
  18. 'serve_js' => TRUE,
  19. 'serve_css' => TRUE,
  20. ],
  21. ];
  22. $settings['flysystem'] = $schemes;

Endpoint is for communicating with Minio, cname is the base URL that files is going to get on the site. Serve_js and serve_css is for Minio to store aggregated CSS and JS.

Create a field

You now need to define which fields are going to use the S3 storage, for this, I create a new image reference field, and use “Flysystem: s3” as the Upload destination.

Surf over to Minio - our example is on - add the defined bucket, my-site, and make sure that drupal can write to it (edit policy in Mino and make sure it has read and write on the prefix - or for wildcard prefix - *)

And you are done

And that is it - now we are using Minio for storing the images. Try to upload a file on the field you created - and you should see the file in Minio. Also on the site - you should of course see the image - but now with the URL used in the settings for CNAME, in our case,

We have put some time and effort into the Flysystem S3 module together with other contributors, and we hope you will test it out and report any feedback. Have fun!