Some times you want to add an external storage for your avatars, photos, or documents.
This is useful in particular if you install Monica on a stateless volatile instance, like Heroku, Platform.sh, etc.
We currently only support AWS S3 driver as external storage.
You need to define at least these environment variables:
FILESYSTEM_DISK=s3
AWS_BUCKET=
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
See below for more details about each environment variable.
- Go to the S3 console
- Add a new bucket
- Save the name and location of the bucket in
AWS_BUCKET
andAWS_DEFAULT_REGION
variables
AWS_BUCKET=my-bucket
AWS_DEFAULT_REGION=eu-west-3
You can also use AWS CLI to create the bucket:
aws s3 mb s3://my-bucket
-
Create a new user via the console.
-
Add the strategy for S3 access, for instance
AmazonS3FullAccess
is a good choice:- add the user to a group with the right strategy
- or attach the strategy directly.
-
Save credentials of the user in
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
variables
AWS_ACCESS_KEY_ID=AKXA3E2NYF7NPDJVQSOU
AWS_SECRET_ACCESS_KEY=aASalDme6wB8kGC7Xla6K3pI+FiFylpCVnGCmdnD
You can also use AWS CLI to set credentials:
aws iam create-user --user-name user-monica-test
aws iam attach-user-policy --user-name user-monica-test --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess
aws iam create-access-key --user-name user-monica-test
Output:
{
"AccessKey": {
"UserName": "user-monica-test",
"AccessKeyId": "AKIAXE2N0F6NIMZXLCGB",
"Status": "Active",
"SecretAccessKey": "Lh5ValIoe9xlfrhkpqiZOub1TFFo4qn1sAdFvlOM",
"CreateDate": "2020-04-12T11:35:06+00:00"
}
}
Then save AccessKeyId
and SecretAccessKey
in AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
variables.
Set the FILESYSTEM_DISK
variable to use S3 storage:
FILESYSTEM_DISK=s3
AWS_ENDPOINT variable can be used to define a S3-compatible provider other than Amazon, like Digitalocean, Scaleway or Minio.
example: AWS_ENDPOINT=nyc3.digitaloceanspaces.com
If you previously used local storage and want to move all avatars to a new S3 storage, use monica:moveavatars
command once to move all files:
php artisan monica:moveavatars