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
composer install "memory" kiwa "ext-simplexml missing" error deto tevha students gondhaltat. SDK la php-xml (SimpleXML) aani php-mbstring lagtat – php -m madhe te distat ka bagha. Aani Composer sudo ne chalvu naka; aadhi folder cha owner ec2-user kara, mag normal user ne chalva.
Lab
Install LEMP and Composer, create /var/www/reels with composer.json, run composer install and composer audit, and confirm vendor/autoload.php exists.