Skip to main content

Sulu Media Storage on IONOS Cloud S3

· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

Sulu CMS can be configured to upload media files directly to an external storage provider, like AWS S3 or Google Cloud Storage. But what about IONOS Cloud S3?

For a customer project, we decided not to store the media files on the Sulu server but use some cloud storage instead. Since we host the Sulu instance at IONOS Cloud, their S3 service would be ideal for media storage.

To let Sulu CMS store the media files on S3, we need to install additional Composer dependencies first:

composer require "league/flysystem:^1.0" "league/flysystem-aws-s3-v3:^1.0.1"

Next, a Sulu config file for production mode only config/packages/prod/sulu_media.yaml has to be created with the following content:

sulu_media:
format_manager:
default_imagine_options:
jpeg_quality: 90
webp_quality: 90
avif_quality: 90
storage: s3
storages:
s3:
key: '%env(SULU_S3_KEY)%'
secret: '%env(SULU_S3_SECRET)%'
bucket_name: '%env(SULU_S3_BUCKET_NAME)%'
region: '%env(SULU_S3_REGION)%'
endpoint: '%env(SULU_S3_ENDPOINT)%'

This allows us to store the files locally in our development environment and use S3 only for production deployments.

At first, it seemed to work fine, as media could be uploaded and deleted via Sulu Admin without any issues. However, in the frontend, the url to the files stored on S3 was not "correct" as Sulu CMS created the links with a double slash, which IONOS Cloud S3 did not like, e.g. https://s3.eu-central-3.ionoscloud.com//sulu-bucket/06/save.png

Luckily, the Sulu CMS team already had thought of this and added a new config option in Sulu 2.6 to configure the public_url for the S3 storage. I had to adapt the config in config/packages/prod/sulu_media.yaml to make it work:

sulu_media:
format_manager:
default_imagine_options:
jpeg_quality: 90
webp_quality: 90
avif_quality: 90
storage: s3
storages:
s3:
key: '%env(SULU_S3_KEY)%'
secret: '%env(SULU_S3_SECRET)%'
bucket_name: '%env(SULU_S3_BUCKET_NAME)%'
region: '%env(SULU_S3_REGION)%'
endpoint: '%env(SULU_S3_ENDPOINT)%'
public_url: 'https://s3.eu-central-3.ionoscloud.com/sulu-bucket'