DEV Community

Viktor Le
Viktor Le

Posted on

How to setup Amazon S3 Compatible Filesystems - MinIO on MacOS for Laravel Application

By default, your application's filesystems configuration file contains a disk configuration for the s3 disk. In addition to using this disk to interact with Amazon S3, you may use it to interact with any S3-compatible file storage service , and MiniIO is the greate choice here.

Let's say, the .env file has this block

FILESYSTEM_DISK=s3 AWS_ACCESS_KEY_ID=access_key AWS_SECRET_ACCESS_KEY=secrete_key AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET=xxxxxxx AWS_ENDPOINT=xxxxxxx 
Enter fullscreen mode Exit fullscreen mode

There are two ways to setup MiniIO locally

  1. Set up directly in the localhost Easy step with 1 command
brew install minio/stable/minio 
Enter fullscreen mode Exit fullscreen mode

Then launch the MinIO Server by running the following command. If desired, you can replace ~/data with another localtion of Storage to read, write and delete access for the MinIO instance

export MINIO_CONFIG_ENV_FILE=/etc/default/minio minio server ~/data --address :9001 ### API (S3 compatible) minio server ~/data --console-address :9002 ### Web UI (User Interface) 
Enter fullscreen mode Exit fullscreen mode

After you run these above commands, it will print out

Status: 1 Online, 0 Offline. API: http://192.168.2.100:9001 http://127.0.0.1:9001 RootUser: myminioadmin RootPass: minio-secret-key-change-me Console: http://192.168.2.100:9002 http://127.0.0.1:9002 RootUser: myminioadmin RootPass: minio-secret-key-change-me Command-line: https://min.io/docs/minio/linux/reference/minio-mc.html $ mc alias set myminio http://10.0.2.100:9001 myminioadmin minio-secret-key-change-me Documentation: https://min.io/docs/minio/linux/index.html 
Enter fullscreen mode Exit fullscreen mode

Now, you have access_key and secrete_key which is RootUser, and RootPass. And let's paste to the .env file

FILESYSTEM_DISK=s3 AWS_ACCESS_KEY_ID=myminioadmin AWS_SECRET_ACCESS_KEY=minio-secret-key-change-me AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET=<name_bucket_desire> AWS_ENDPOINT=http://127.0.0.1:9001 
Enter fullscreen mode Exit fullscreen mode

You can connect and interact with MinIO from Laravel Application

Open browser with address: http://127.0.0.1:9002, bummmm MinIO UI appears excellently

Image description

  1. Setup by using Docker the docker-compose.yml will look like
version: '3.8' services: minio: image: quay.io/minio/minio:latest # Or your preferred MinIO image container_name: minio ports: - "9001:9001" # Expose the MinIO server port - "9002:9002" # Expose the MinIO console port environment: MINIO_ACCESS_KEY: minioadmin # Replace with your desired username MINIO_SECRET_KEY: minioadmin # Replace with your desired password MINIO_DEFAULT_BUCKETS: "my-test-bucket" # Optional: create a default bucket volumes: - ./data:/data # Persistent storage for MinIO data command: server /data --address ":9001" --console-address ":9002" # Start MinIO server with console on port 9001 restart: unless-stopped # Restart policy for the container 
Enter fullscreen mode Exit fullscreen mode

And all the rest is like the option#1 to connect and interact with MinIO

Reference:

  1. https://laravel-news.com/minio-s3-compliant-storage
  2. https://min.io/docs/minio/macos/index.html

Top comments (0)