16. Live Project: Building a Reels App with EC2, S3 and RDS
16.12 Testing and Troubleshooting
| Symptom | Likely cause | Check / fix |
|---|---|---|
502 Bad Gateway |
PHP-FPM stopped or wrong socket | sudo service php-fpm status; ls /run/php-fpm/ (Ubuntu /run/php/) |
Blank page / 500 |
PHP error | sudo tail -f /var/log/php-fpm/www-error.log (Ubuntu: /var/log/nginx/error.log) |
413 Request Entity Too Large |
Nginx body limit | client_max_body_size 60M; then nginx -t and reload |
| "Upload failed (error code 1)" | PHP upload_max_filesize too small |
Check 99-reels.ini, restart PHP-FPM |
| "Could not store the video" | IAM role missing/wrong, wrong bucket or region | Log shows AWS error code; aws sts get-caller-identity; policy resource videos/* |
SQLSTATE[HY000] [2002] |
Can't reach RDS | nc -zv <endpoint> 3306; db-sg source = web-sg |
SQLSTATE[HY000] [1045] |
Wrong DB user/password | Test with mysql -h ... -u reels_app -p |
| Videos don't play, 403 in Network tab | Presigned URL expired or signed for wrong region | Reload page; aws_region must match the bucket |
| Videos blocked, CSP error in console | media-src doesn't match the bucket host |
Put your exact bucket host in the CSP header |
| Login loops back to login page | Secure cookie over HTTP, or session dir not writable | Use HTTPS; ls -ld /var/lib/php/session |
sudo tail -f /var/log/nginx/access.log /var/log/nginx/error.log
sudo tail -f /var/log/php-fpm/www-error.log # Amazon Linux 2023
curl -s -o /dev/null -w "%{http_code}\n" https://reels.yourdomain.com/feed.php # 401 when logged out
Ravindra Bagale's Tip
When an error appears, students start changing the code. Read the log first! Most of the time the answer is right there in error.log. Remember the order: browser DevTools (Network/Console) → Nginx error log → PHP-FPM log → AWS/RDS connectivity. Use this order and you'll find any problem quickly.
Ravindra Bagale's Tip – मराठी
Error आला की students code बदलायला लागतात. आधी log वाचा! बहुतेक वेळा उत्तर error.log मध्येच असतं. क्रम लक्षात ठेवा: browser DevTools (Network/Console) → Nginx error log → PHP-FPM log → AWS/RDS connectivity. हा क्रम वापरला तर कोणताही problem लवकर सापडतो.
Ravindra Bagale's Tip – हिंदी
Error आते ही students code बदलने लगते हैं. पहले log पढ़ो! ज़्यादातर जवाब error.log में ही होता है. क्रम याद रखो: browser DevTools (Network/Console) → Nginx error log → PHP-FPM log → AWS/RDS connectivity. यह क्रम इस्तेमाल करो तो कोई भी problem जल्दी मिल जाती है.
Practice task
Break the app on purpose three ways – stop PHP-FPM, detach the IAM role, remove the 3306 rule – and note the exact error and log line for each. Then fix them. This is exactly how you will think during incident response.