3.2 KiB
External storage
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.
Configure an external storage
You need to define at least these environment variables:
DEFAULT_FILESYSTEM=s3
AWS_BUCKET=
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
See below for more details about each environment variable.
Add an external storage
1. Create AWS S3 storage
- Go to the S3 console
- Add a new bucket
- Save the name and location of the bucket in
AWS_BUCKETandAWS_DEFAULT_REGIONvariables
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
2. Create a user
-
Create a new user via the console.
-
Add the strategy for S3 access, for instance
AmazonS3FullAccessis 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_IDandAWS_SECRET_ACCESS_KEYvariables
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.
3. Set environment variables
Set the DEFAULT_FILESYSTEM variable to use S3 storage:
DEFAULT_FILESYSTEM=s3
(Optional) Use another S3 provider
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
Move avatars to S3 storage
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