AWS Solutions Architect · Module 4 · Day 12

Linux File Commands & Web Servers on EC2

⏱ 16 min read🎯 Beginner friendly🖼 3 diagrams🧪 4 live demos🐍 Python code

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

TaskCommand
Create a foldermkdir project
Create nested foldersmkdir -p site/css/img
Hidden foldermkdir .secret (see it with ls -a)
Rename / movemv old new · mv project /tmp/
Copy a foldercp -r site site-backup
Delete an empty folderrmdir old
Delete a folder and everything in itrm -rf site-backup
Empty filetouch notes.txt
Delete a filerm 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 modeDoesRemember
cat fileview the fileread
cat > filecreate / overwrite (type text, then Ctrl+D)> = wipe and write
cat >> fileappend 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

vi / vim• on EVERY Linux system• has modes: command and insert• i = start typing, Esc = stop• :wq save & quit · :q! quit without savingnano• easy, shortcuts shown at the bottom• just start typing• Ctrl+X → Y → Enter to save & exit• may need installing on some systems
Two editors. Learn nano first; learn the 4 vi keys too, because vi is always there.
Demo · Editing a file in vi

03What is a web server?

Browserhttp://public-IPSecurity groupis port 80 open?EC2 instanceIIS or Apacheindex.htmlthe page
A web server is software that sends web pages to browsers. Port 80 must be open or the browser just times out.
WindowsUbuntuAmazon Linux
SoftwareIISApache (apache2)Apache (httpd)
Website folderC:\inetpub\wwwroot/var/www/html/var/www/html
Install withServer Manager or PowerShellaptdnf
Log in withRDP 3389SSH 22SSH 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
CommandMeaning
apt / dnfpackage managers (app store for the command line) on Ubuntu / Amazon Linux
systemctl startstart a service now
systemctl enablestart it automatically at boot
systemctl statusis 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?
UsersLoad balancerHTTPS 443 with an ACM certificateAuto Scaling groupweb servers in 2+ AZsDatabaseprivate subnet
The production pattern you will build later: no single server, HTTPS, automatic scaling, private database.
🎯 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

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

Created by Ajeetkumar