Secure .env-based approach for AWS S3 image uploads in Sendy
https://github.com/tpyo/amazon-s3-php-class
- Source:
dev/includes/helpers/S3.php - Deploy to:
sendy/includes/helpers/S3.php
- Source:
dev/includes/create/upload-final.php - Deploy to:
sendy/includes/create/upload.php - Action: Replace the existing upload.php file (backup original first!)
- Source:
dev/.env-production - Deploy to:
sendy/.env - Action: Contains AWS credentials (configure before deploying)
- Create an S3 bucket or use existing one
- Note your bucket name and region
- Important: Modern S3 buckets have ACLs disabled - this is handled automatically
Create an IAM user with this policy (replace YOUR_BUCKET_NAME):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}Edit dev/.env-production before deployment:
# AWS S3 Configuration for Sendy Image Uploads
AWS_ACCESS_KEY_ID=your_actual_access_key
AWS_SECRET_ACCESS_KEY=your_actual_secret_key
S3_BUCKET=your-bucket-name
S3_REGION=your-region (e.g., us-west-2)Ensure your php.ini has these settings:
upload_tmp_dir = /tmp
upload_max_filesize = 10M
post_max_size = 10MDocker Installation:
docker cp sendy:/var/www/html/includes/create/upload.php /tmp/upload.php.backupDirect Installation:
cp /var/www/html/includes/create/upload.php /tmp/upload.php.backup
# Or wherever your Sendy installation is located- Edit
dev/.env-productionwith your actual AWS credentials - Update S3_BUCKET and S3_REGION values
Docker Installation:
# Copy files to server temp directory
scp dev/includes/helpers/S3.php user@server:/tmp/
scp dev/includes/create/upload-final.php user@server:/tmp/
scp dev/.env-production user@server:/tmp/.env
# Deploy to Docker container
docker cp /tmp/S3.php sendy:/var/www/html/includes/helpers/
docker cp /tmp/upload-final.php sendy:/var/www/html/includes/create/upload.php
docker cp /tmp/.env sendy:/var/www/html/Direct Installation:
# Copy files directly to Sendy installation
scp dev/includes/helpers/S3.php user@server:/var/www/html/includes/helpers/
scp dev/includes/create/upload-final.php user@server:/var/www/html/includes/create/upload.php
scp dev/.env-production user@server:/var/www/html/.env
# Or if copying locally:
cp dev/includes/helpers/S3.php /var/www/html/includes/helpers/
cp dev/includes/create/upload-final.php /var/www/html/includes/create/upload.php
cp dev/.env-production /var/www/html/.envDocker Installation:
# Set ownership to web server user
docker exec sendy chown www-data:www-data /var/www/html/includes/helpers/S3.php
docker exec sendy chown www-data:www-data /var/www/html/includes/create/upload.php
docker exec sendy chown www-data:www-data /var/www/html/.env
# Set file permissions
docker exec sendy chmod 644 /var/www/html/.env
docker exec sendy chmod 644 /var/www/html/includes/create/upload.php
docker exec sendy chmod 644 /var/www/html/includes/helpers/S3.phpDirect Installation:
# Set ownership to web server user (adjust user as needed: www-data, apache, nginx)
chown www-data:www-data /var/www/html/includes/helpers/S3.php
chown www-data:www-data /var/www/html/includes/create/upload.php
chown www-data:www-data /var/www/html/.env
# Set file permissions (important for .env security)
chmod 644 /var/www/html/.env
chmod 644 /var/www/html/includes/create/upload.php
chmod 644 /var/www/html/includes/helpers/S3.phpNote: Replace www-data with your web server user:
- Ubuntu/Debian:
www-data - CentOS/RHEL:
apache - Some configurations:
nginx
Docker Installation:
docker exec sendy ls -la /var/www/html/.envDirect Installation:
ls -la /var/www/html/.envShould show: -rw-r--r-- 1 www-data www-data (or your web server user)
- Try uploading an image through Sendy's editor
- Check browser console for any error messages
- Verify image appears in your S3 bucket at
s3://your-bucket/sendy/images/
-
"AWS credentials not configured"
- Check .env file exists:
docker exec sendy cat /var/www/html/.env - Verify .env file permissions:
docker exec sendy ls -la /var/www/html/.env - Ensure .env file owned by www-data:
chown www-data:www-data /var/www/html/.env
- Check .env file exists:
-
"The bucket does not allow ACLs"
- Modern S3 buckets disable ACLs by default - this is handled in upload-final.php
- Ensure you're using the updated upload script without ACL parameters
-
"S3 upload failed"
- Check bucket name and region are correct in .env file
- Verify IAM user has proper permissions
- Test credentials with:
aws s3 ls s3://your-bucket-name --region your-region
-
Permission denied errors
- All files must be owned by www-data:www-data
- .env file must be readable by web server (644 permissions)
- Upload script must be executable by web server
The upload script includes console logging. Check browser developer tools console for detailed error messages.
sendy/
├── includes/
│ ├── create/
│ │ └── upload.php (updated with S3 functionality)
│ └── helpers/
│ └── S3.php (new file)
- Never commit AWS credentials to version control
- Use IAM users with minimal required permissions
- Regularly rotate AWS access keys
- Monitor S3 bucket access logs