AWS Solutions Architect · Module 4 · Day 12
Linux File Commands & Web Servers on EC2
Today you bring it all together. First you learn to create, edit, copy, move and delete files in Linux (try them in the practice terminal). Then you publish a real website from EC2, once on Windows (IIS) and once on Linux (Apache), using ports (Day 5), security groups (Day 8), RDP (Day 9) and SSH (Day 10).
In this session
- Directory commands: mkdir, mv, cp -r, rmdir, rm -rf
- File commands: touch, cat (view, overwrite, append), rm
- Editors: vi/vim and nano
- What a web server is, and opening port 80
- Lab: IIS on Windows
- Lab: Apache on Ubuntu and Amazon Linux
- Troubleshooting and the production way
01Folder and file commands
| Task | Command |
|---|---|
| Create a folder | mkdir project |
| Create nested folders | mkdir -p site/css/img |
| Hidden folder | mkdir .secret (see it with ls -a) |
| Rename / move | mv old new · mv project /tmp/ |
| Copy a folder | cp -r site site-backup |
| Delete an empty folder | rmdir old |
| Delete a folder and everything in it | rm -rf site-backup |
| Empty file | touch notes.txt |
| Delete a file | rm notes.txt (rm -i asks first) |
🛑 Danger: Linux has no recycle bin.
rm -rf deletes instantly. Run pwd first and never run rm -rf /.| cat mode | Does | Remember |
|---|---|---|
cat file | view the file | read |
cat > file | create / overwrite (type text, then Ctrl+D) | > = wipe and write |
cat >> file | append to the end | >> = add more |
Demo · Practice terminal
Try: mkdir -p site/css, echo hello > site/index.html, cat site/index.html, cp -r site site-bak, ls, rm -r site-bak.
02Editors: vi and nano
Demo · Editing a file in vi
03What is a web server?
| Windows | Ubuntu | Amazon Linux | |
|---|---|---|---|
| Software | IIS | Apache (apache2) | Apache (httpd) |
| Website folder | C:\inetpub\wwwroot | /var/www/html | /var/www/html |
| Install with | Server Manager or PowerShell | apt | dnf |
| Log in with | RDP 3389 | SSH 22 | SSH 22 |
Open port 80: instance → Security tab → security group → Edit inbound rules → Add rule → HTTP → Source Anywhere-IPv4 → Save.
04Lab: IIS on Windows
Demo · Do it yourself
PowerShell (as Administrator): the fast way
Install-WindowsFeature -Name Web-Server -IncludeManagementTools Set-Content -Path C:\inetpub\wwwroot\index.html -Value "<h1>Hello from IIS on EC2</h1>"
Common trap: Windows hides file extensions, so your file may really be
index.html.txt. Turn on View → Show → File name extensions.05Lab: Apache on Ubuntu (and Amazon Linux)
Ubuntu
sudo -i # become root apt update -y # refresh the package list apt install apache2 -y # install the Apache web server systemctl start apache2 # start it now systemctl enable apache2 # start it automatically after every reboot systemctl status apache2 # should say "active (running)" (press q) cd /var/www/html/ rm -f index.html # remove the default page nano index.html # type your page, then Ctrl+X, Y, Enter
index.html
<h1>Hello from my Ubuntu web server on AWS!</h1> <p>Served by Apache on EC2.</p>
Amazon Linux 2023
sudo -i dnf install httpd -y systemctl start httpd systemctl enable httpd echo "<h1>Hello from Amazon Linux</h1>" > /var/www/html/index.html
| Command | Meaning |
|---|---|
apt / dnf | package managers (app store for the command line) on Ubuntu / Amazon Linux |
systemctl start | start a service now |
systemctl enable | start it automatically at boot |
systemctl status | is it running? |
Automate it: paste the Amazon Linux commands (without
sudo -i, starting with #!/bin/bash) into User data when launching, and the instance becomes a web server by itself on first boot.06Troubleshooting and the production way
Demo · What went wrong?
- A static site (HTML/CSS/JS only) can be hosted on Amazon S3 + CloudFront with no server at all.
- Keep SSH/RDP closed to the world; open only 80/443. Patch regularly.
- Logs:
/var/log/apache2/(Ubuntu),/var/log/httpd/(Amazon Linux),C:\inetpub\logs\LogFiles(IIS).
🎯 Exam corner
- Website on EC2 unreachable → security group must allow 80/443.
- Install software automatically at launch → user data.
- Static website, no servers → S3 static website hosting + CloudFront.
- Spread traffic over servers → Elastic Load Balancer.
07Summary
- Folders:
mkdir -p,mv,cp -r,rmdir,rm -rf(no recycle bin!). - Files:
touch,cat(view),>overwrite,>>append; editors nano and vi (i, Esc, :wq, :q!). - Website on EC2: open port 80, install IIS or Apache, put index.html in
wwwrootor/var/www/html. systemctl startnow,enableat boot.- Production: load balancer + Auto Scaling + HTTPS; static sites on S3 + CloudFront.
08Quick quiz
1. Command to copy folder site to site-bak?
2. Difference between cat > a.txt and cat >> a.txt?
3. Quit vi without saving?
4. Where does Apache serve files from?
5. Browser times out on your EC2 website. Check first?
09References
- Tutorial: install a LAMP server on Amazon Linux 2023
- Run commands at launch with user data
- Hosting a static website on Amazon S3
Created by Ajeetkumar