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.