How to store WordPress media files to Amazon S3 bucket

How to store WordPress media files to Amazon S3 bucket


How to store WordPress media files to Amazon S3 bucket

Today in this video, we are going to learn how to store the WordPress media files in the S3 bucket of AWS.
Login to the AWS console.
In S3, before creating an s3 bucket, navigate to block public access settings for this account. In block public access settings, click on the edit button. Here uncheck the first two checkboxes and check the last two checkboxes.
Now it’s time to create the s3 bucket to store all the media files of the WordPress site. In the buckets section, create a new bucket. Give an appropriate name of the bucket. Select your current region. ACLs disable recommended, fine.

Block public access settings, checked the option same as previous. Unchecked the two options and checked the last two options.
Acknowledge public access.
Create Bucket.
Navigate to the IAM page. Before creating a new user, let’s create a separate policy for it.
Create Policy.
Open the JSON tab.
Paste the policy code.
{
“Version”: “2012-10-17”,
“Statement”: [{
“Sid”: “VisualEditor0”,
“Effect”: “Allow”,
“Action”: [
“s3:PutObject”,
“s3:GetObjectAcl”,
“s3:GetObject”,
“s3:PutBucketAcl”,
“s3:ListBucket”,
“s3:DeleteObject”,
“s3:GetBucketAcl”,
“s3:GetBucketLocation”,
“s3:PutObjectAcl”
],
“Resource”: [
“arn:aws:s3:::your bucket name”,
“arn:aws:s3:::your bucket name/*”
]
}
]
}
Copy the bucket name, and paste it. Here as well.
Provide an appropriate name for the policy. Describe the policy so that it can help in the future to understand for what purpose this policy was created.
Create policy.
Navigate to the user’s page.
Click the add users button to add a new user who can access our s3 bucket.
Provide an appropriate name for it.
In the select AWS access type, checked the access key programmatic access.
Select the attach existing policies directly option. Search for the policy which you have just created before. Here it is mine, select it.
Create user.
Copy the access key id and secret access key which we need to configure in our WordPress site to give access to our s3 bucket.
Please don’t forget to save it properly coz we can’t view it again as we close this page.

Ok, now it’s time to move to the WordPress site.
Let’s install a fresh WordPress site.
Currently, I’m working on the default theme.
Navigate to the Plugin menu, and add a new plugin. Search plugin wp offload — wp offload media lite for Amazon s3.
Install it – Activate it as well.
Open the plugin setting page.
You must set your storage provider access credentials to enable bucket access.
Select Provider - we are using Amazon s3
Connection method - define access keys in the wp-config.php file.
Copy the code and navigate to the wp-config file.
Paste the code.
Add any custom values between this line and the stop editing line.
We need to replace the * with the access key id and secret access key.
Navigate back to settings, here the page will refresh automatically.
Refresh the page.
Copy the bucket name and paste it.
Save bucket settings.
Here both block all public access and object ownership are disabled. Which should be disabled and if we try to enable it, it will not be allowed to do so.
Could not change block all public access status for a bucket.
We are not storing any media files locally. So enable remove local media option as well.
In check in delivery settings. I’m using HTTPS on the site so let’s enable the force HTTPS option as well.
Save changes.
Check whether it is all fine or not by uploading images to the media.
Open the Media library and add new. Select files.
The path of the image is in the local system, not in the s3 bucket.
Delete the image and go for the solution.

Navigate to the wp offload media lite plugin setting, and check all settings. Seems all fine.
What we have to do over here is, we have to enable both - block all public access and object ownership for once and disable it again.
Update changes, — could not change it.

For that, we have to assign the current IAM user to the s3 bucket full access once.

Navigate to the IAM page on AWS.
Click on the add permission button.
Again select the same option - attach existing policies directly and search for s3.
Amazon s3 full access - checked it.
Navigate back to the offload setting. Let’s refresh once before we process ahead.
Enable both security settings.
Settings locked, requesting refresh the page.
Warnings. Disable it again.
Update bucket security.
Upload image to the media library.
Check the path of the image.
In this way, we can set up and manage to store all media files of the WordPress site in the AWS s3 bucket.

SUBSCRIBE to our YouTube channel for more videos: https://www.youtube.com/c/Master2Teac

Like us on Facebook: https://www.facebook.com/master2teach

For more content go to https://master2teach.com/


Content

0 -> Hello Everyone Welcome to Master2Teach Step by Step guide.
11.1 -> Today in this video, we are  going to learn how to store  
14.7 -> the WordPress media files in the S3 bucket of AWS.
18.24 -> Please don’t forget to like, share,  and subscribe to the channel. Please  
22.56 -> feel free to leave a comment  in the comment section below.
26.1 -> Ok, here I’m already login to the AWS  console. We are starting from S3. In S3,  
33.42 -> before creating an s3 bucket, navigate to  block public access settings for this account.  
43.56 -> In block public access settings,  click on the edit button.  
47.58 -> Here uncheck the first two checkboxes  and check the last two checkboxes.
56.16 -> Click on Save changes. Type Confirm to confirm it.
62.88 -> Now it's time to create the s3 bucket to store  all the media files of the WordPress site.  
69.3 -> In the buckets section, create a new bucket.  Give an appropriate name of the bucket.  
80.22 -> Select your current region. I’m from Nepal so my  nearest region is Asia Pacific Mumbai. You can  
88.08 -> select your own but make sure it should be the  correct region. ACLs disable recommended, fine.
94.5 -> Block public access settings,  checked the option same as previous.  
99.84 -> Unchecked the two options and  checked the last two options.
104.64 -> Acknowledge public access.
107.34 -> Bucket versioning - Fine.
109.26 -> Tags - not necessary for now. Default encryption, Fine.
113.34 -> Create Bucket.
117.78 -> Here is a bucket, ok here  is a new s3 bucket created.
123.06 -> Now, moving to the next step, that is creating  an IAM user. Navigate to the IAM page.  
139.86 -> Before creating a new user, let’s  create a separate policy for it.
145.02 -> Create Policy.
148.68 -> This is a visual editor. Open the JSON tab.
154.62 -> Paste the policy code over here. You  can find this code in the description  
158.94 -> below as well as on the site master2teach.com.
165.12 -> We need to mention the bucket name over here.  Copy the bucket name, and paste it. Here as well.
181.62 -> Click the Next tag button. Tags are  not necessary for now. Next: Review.
187.32 -> Provide an appropriate name for the policy.  
194.64 -> Describe the policy so that it can help in  
197.34 -> the future to understand for what  purpose this policy was created.
204.78 -> Let’s create it.  
215.1 -> The policy master2teach policy has been created.
218.64 -> Ok, Let’s move further.
220.44 -> Navigate to the user's page.
224.16 -> Click the add users button to add a  new user who can access our s3 bucket.
229.5 -> Provide an appropriate name for it.
234.72 -> In the select AWS access type, checked  the access key programmatic access.
239.76 -> Next - Permission.
240.96 -> Select the attach existing  policies directly option.  
244.92 -> Search for the policy which you have just  created before. Here it is mine, select it.
251.1 -> Next: tags
252.9 -> We are escaping tags for now.  Next Review. Seems all fine.
257.52 -> Create user.
262.74 -> Ok, there is the access key id and  secret access key which we need to  
267.54 -> configure in our WordPress site  to give access to our s3 bucket. 
271.5 -> Please don’t forget to save it properly coz  we can’t view it again as we close this page.
286.68 -> Ok, now it's time to move to the WordPress site.
291.96 -> I’m working on my site for now Lokanthali.com
294.96 -> Let’s install a fresh WordPress site.
317.46 -> Here is the WordPress dashboard page.  Currently, I'm working on the default theme.
331.14 -> Navigate to the Plugin menu, and add a new plugin.  
336.48 -> Search plugin wp offload — here it is,  wp offload media lite for Amazon s3.
345.78 -> Install now –  
352.26 -> Activate it as well.
355.14 -> Open the plugin setting page.
358.68 -> You must set your storage provider access  credentials to enable bucket access.
363.12 -> Let’s process it.
365.22 -> Select Provider - we are using Amazon s3
368.22 -> Connection method - define access  keys in the wp-config.php file.
373.38 -> Here is a code that we need  to add to our wp-config file. 
376.74 -> Let’s copy it and navigate to the wp-config file.
380.7 -> I’m going to edit it live over  here from the file manager. Edit.
388.86 -> Scroll down, and paste the code over here. 
393.54 -> Add any custom values between this  line and the stop editing line.
397.62 -> We need to replace the * with the  access key id and secret access key.
403.2 -> Copy it, and paste it over here. 
412.02 -> Again Copy it, and paste it over here.
418.8 -> Great, Done - Save changes.
422.22 -> Ok Great, navigate back to settings,  here the page will refresh automatically.
430.38 -> It's processing.
438.72 -> Ok, refresh the page.
440.58 -> Great
443.58 -> Select the bucket.
444.72 -> Copy the bucket name and paste it over here.
448.62 -> Copy it, and paste it.
454.02 -> Save bucket settings.
461.64 -> Here both block all public access  and object ownership are disabled.  
466.5 -> Which should be disabled and if we try to  enable it, it will not be allowed to do so.
473.22 -> Let's check it.
480.96 -> Could not change block all public  access status for a bucket.
487.08 -> Ok, let’s keep it disabled for now.
496.68 -> We are not storing any media files locally.  So enable remove local media option as well.
503.94 -> Save changes.
509.46 -> Add prefix to bucket path. 
512.88 -> In the s3 bucket, — here wp-content  and uploads prefixes will be added.
519.9 -> Similarly, the year and month folders  will be added to the s3 bucket.
524.94 -> Same as the object version to the bucket path.
527.4 -> Here the media path will look like this.
530.64 -> Ok, let’s move ahead. In  check in delivery settings.  
535.8 -> I'm using HTTPS on the site so let’s  enable the force HTTPS option as well.
542.04 -> Save changes.
544.38 -> Here it is.
545.22 -> Ok now let’s check whether it is all fine  or not by uploading images to the media. 
551.16 -> Open the Media library and add new. Select  files. Here is my picture, let’s try it.
561.12 -> Uploading in progress.
563.52 -> Here it goes. Let’s check the path of the image.
567 -> The path of the image is in the  local system, not in the s3 bucket.
573.72 -> Let’s delete it and go for the solution.
578.4 -> Navigate to the wp offload media lite  plugin setting, and check all settings.  
589.44 -> Seems all fine.
601.08 -> What we have to do over here is, we have to enable  
604.56 -> both - block all public access and object  ownership for once and disable it again.
610.62 -> Update changes, — could not change it.
615.3 -> For that, we have to assign the current  IAM user to the s3 bucket full access once.
621.18 -> Let’s do that.
622.26 -> Navigate to the IAM page on AWS.
624.6 -> We have all done with these keys,  we can leave them now. Open IAM
637.5 -> Click in the user,--- open it.
647.16 -> Click on the add permission button. Again select the same option - attach  
651.9 -> existing policies directly and search for s3.
655.44 -> Here is amazon s3 full access - checked it.
659.1 -> Next review -
660.27 -> Add permissions
664.38 -> Here it goes. Ok, navigate  back to the offload setting.  
669.54 -> Let’s refresh once before we process ahead.
674.4 -> Ok, let’s enable both security settings.
678.3 -> Ok settings locked, requesting refresh the page.
685.98 -> Here are the warnings.  
698.52 -> Let’s disable it again.
700.02 -> Unchecked, — Unchecked
702.36 -> Update bucket security.
709.56 -> Ok all done now. Seems all good  now. Let’s check by refreshing  
714.72 -> the page as well if we get any warnings. Ok Fine.
720 -> Let’s check by uploading  images to the media library.
722.94 -> Select files
724.14 -> I’m uploading the same image. Open
727.5 -> Uploading in progress.
728.88 -> Here it goes. Let’s check the path of the image.
733.68 -> Ya, you can see the file URL in the  s3 bucket which we created before. 
738 -> Great Job. Let’s check in the new tab. Ya, it’s all good.
744.72 -> Also, let’s check in the s3  bucket. Refresh the page.  
754.5 -> Ok, a wp-content folder is  created. Let’s check the full path.
759.12 -> Bucket —  
761.4 -> Master2teach Bucket — wp content – uploads –  year – month – object key – images as objects.
769.92 -> Also, let’s check if the images are  uploaded to a local server or not. 
777.36 -> Wp- content – uploads – year – month – it's empty.  
785.16 -> These folders were created  when we tried them before.
789.18 -> In this way, we can set up and manage to store all  
792 -> media files of the WordPress  site in the AWS s3 bucket.
795.12 -> Let’s review the offload plugin setting once.
797.82 -> Make sure you have selected the correct region.
806.64 -> Enable the removal of local media and all these.
813.96 -> In delivery settings, both options are enabled.
823.08 -> Navigate to the edit option of Amazon s3 Provider and connection methods are both ok. 
828.72 -> In the bucket, make sure you input  the correct bucket name over here.
833.16 -> And last but not least option security,  
836.22 -> make sure both are disabled and make sure you  have once enabled it and again disable it.
842.1 -> Once all is working fine, you can remove the  amazons3fullaccess permission to IAM users.
848.22 -> Detach from the user.
853.92 -> Refresh and confirm.  
860.52 -> Ok, it's removed now.
862.26 -> Moving back to the WordPress site. Refresh once.  
867.96 -> All is fine here. Navigate to the  media library. Let’s remove it first.
880.02 -> Ok, Add new, select files.
882.36 -> Select it again,---- uploading….
886.32 -> Check the path, ok it’s an s3 bucket.
893.7 -> In this way, we can upload and store all media  files to store in the AWS s3 bucket over here.
899.64 -> I hope you learn from this video  tutorial. Please don’t forget to like,  
903.42 -> share, and subscribe to the channel  if you haven’t already. Thank you for  
907.2 -> watching. See you all soon on  the next video tutorials. Bye

Source: https://www.youtube.com/watch?v=DbYRZBAnthA