16. Live Project: Building a Reels App with EC2, S3 and RDS
16.3 Server Setup: LEMP, Composer and the AWS SDK for PHP
Database RDS var aahe, mhanun EC2 var fakt MySQL client lagto, server nahi.
Amazon Linux 2023
sudo yum update -y
sudo yum install -y nginx php php-fpm php-cli php-mysqlnd php-mbstring php-xml mariadb105 unzip git
sudo service php-fpm start
sudo service nginx start
sudo systemctl enable nginx php-fpm
php -v && php -m | grep -Ei 'pdo_mysql|mbstring|simplexml|fileinfo'
Ubuntu
sudo apt update
sudo apt install -y nginx php-fpm php-cli php-mysql php-mbstring php-xml php-curl mysql-client unzip git composer
sudo service php8.3-fpm start # use the version you see in: ls /run/php/
sudo service nginx start
Composer (the PHP package manager). On Ubuntu it came with apt above. On Amazon Linux 2023 use the official installer (see getcomposer.org/download for the current commands and the installer checksum check):
cd /tmp
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
composer --version
Project folder and the AWS SDK for PHP
sudo mkdir -p /var/www/reels/{src,public/assets,deploy}
sudo chown -R ec2-user:ec2-user /var/www/reels # Ubuntu: ubuntu:ubuntu
cd /var/www/reels
composer.json
{
"name": "ravindra/reels",
"description": "Reels-style video and text feed – Cyber Security Study Guide project",
"require": {
"php": ">=8.1",
"aws/aws-sdk-php": "^3.300"
}
}
composer install --no-dev --optimize-autoloader # downloads aws/aws-sdk-php into vendor/
ls vendor/aws/aws-sdk-php # SDK is installed
Why this matters for security
Libraries are part of your attack surface. composer.lock pins exact versions so every server runs the same tested code; composer audit checks installed packages against known vulnerability advisories. Never run Composer as root on a production server, and never put vendor/ inside the web root.
Ravindra Bagale's Tip
When composer install gives a "memory" or "ext-simplexml missing" error, students get confused. The SDK needs php-xml (SimpleXML) and php-mbstring – check that they appear in php -m. And don't run Composer with sudo; first make ec2-user the owner of the folder, then run it as the normal user.
Ravindra Bagale's Tip – मराठी
composer install "memory" किंवा "ext-simplexml missing" error देतो तेव्हा students गोंधळतात. SDK ला php-xml (SimpleXML) आणि php-mbstring लागतात – php -m मध्ये ते दिसतात का बघा. आणि Composer sudo ने चालवू नका; आधी folder चा owner ec2-user करा, मग normal user ने चालवा.
Ravindra Bagale's Tip – हिंदी
composer install "memory" या "ext-simplexml missing" error दे तो students उलझ जाते हैं. SDK को php-xml (SimpleXML) और php-mbstring चाहिए – देखो कि वे php -m में दिखते हैं या नहीं. और Composer को sudo से मत चलाओ; पहले folder का owner ec2-user बनाओ, फिर normal user से चलाओ.
Lab
Install LEMP and Composer, create /var/www/reels with composer.json, run composer install and composer audit, and confirm vendor/autoload.php exists.
Extended teaching notes
Why this lesson matters
Cloud security is mostly IAM, network exposure, logging and secure defaults. The shared responsibility model means the provider patches the metal; you patch what you configure.
- No public databases or public admin panels.
- Roles / OIDC instead of long-lived access keys.
- CloudTrail / Activity Logs / Audit Logs on and retained.
- S3/Blob/GCS: Block Public Access; encrypt; least privilege.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.