S3 and S3-compatible storage is an indispensable component of modern web applications, especially when deploying with containers like Docker and Kubernetes.
When developing an application locally, although Laravel and other frameworks have unified storage helpers allowing switching between file systems (usually local and S3), there are many quirks of object storage that will be overlooked if using a local filesystem.
Rather than use a hosted S3 system during development, we can save costs, latency (and time) and bandwidth using a local S3-compatible server. MinIO was the go-to until recently with controversial license changes. RustFS is a good choice for local development. Here is how to set it up with Docker and Laravel for local development:
Specifies which HTTP headers are allowed for signed requests. In practice I’ve found this is required when serving large files.
1
rustfs/rustfs:latest
The Docker image to run (latest version of RustFS).
To configure this as a storage disk in Laravel, we can either create a new disk, or alter the S3 disk. You’ll have to decide which approach to take, which may depend on if you have multiple disks and providers.
The admin interface of RustFS is very easy to use. If you are intending files to be public and using Laravel, it is essential to set your file system as public, and also set your RustFS bucket as public. From experience you will just get silent errors with no error logs to help you.
From experience I’ve found that RustFS requires use_path_style_endpoint, as the URL structure has the bucket name as the first path in the URL, contrary to S3. This is the same in many compatible servers.
During development, the option to ignore self-signed certificate errors is important.
The final step is to set up a reverse proxy on your favorite web server to serve the files. Here’s an example config in Nginx (don’t forget to update your hosts file):
That’s it! Now you have local S3-compatible storage for local development, that won’t cost you in storage and ingress/egress fees, has low latency and won’t use up your bandwidth.