AWS S3 PHP - How to open access to a file from PHP
Web links
- https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_installation.html
- Download AWS SDK .ZIP File.
- Login to your website
- Upload the AWS.ZIP into its own folder ie AWS_SDK
- Extract the AWS.ZIP Setup Credentials:
- https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
- https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_profiles.html
- create .aws/ in home directory
- create file called “credentials” in .aws/ folder
Create Bucket
Lock down bucket to a policy:
Errors: PHP Fatal error: Uncaught Error: Call to undefined function JmesPath\mb_strlen() in /home/poultryp/public_html/S3/JmesPath/Lexer.php:343
- https://stackoverflow.com/questions/66179871/php-aws-sdk-fatal-error-creating-s3client
- https://trustiko.com/enable-php-mbstring-extension-in-cpanel/
PHP Fatal error: Uncaught Aws\Exception\CredentialsException: Cannot read credentials from /.aws/credentials in /home/poultryp/public_html/S3/Aws/Credentials/CredentialProvider.php:874
- See “Setup Credentials” above
- If this still happens:
-
putenv(‘HOME=/home/poultryp’);// Needed overwise AWS cannot find home directory
Access Denied:
- https://zenesys.medium.com/grant-iam-user-access-to-only-one-s3-bucket-or-folder-using-iam-policy-6bd3043ae5be
- Make sure to add two resources, one for the Folder/Bucket and one for the files in the bucket:
"Resource": [ "arn:aws:s3:::protectedwebsite", "arn:aws:s3:::protectedwebsite/*" ]
Last modified November 7, 2022: Lots of updates (46e788a)