Ravindra BagaleCourses & study guides

Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)

7.4 Step 2 (common): ways to upload your own files

Option A — scp from your laptop (run on your laptop, not on the server):

# Linux / macOS / Windows PowerShell - upload whole folder to the server's home directory
scp -i mykey.pem -r ./mysite ec2-user@<PUBLIC_IP>:~/
# Ubuntu server:
scp -i mykey.pem -r ./mysite ubuntu@<PUBLIC_IP>:~/

Option B — git clone (run on the server). Push your site to a GitHub repository first:

sudo yum install -y git          # AL2023 / CentOS  (Ubuntu: sudo apt install -y git)
git clone https://github.com/<your-username>/<your-repo>.git ~/mysite
# later, to update:
cd ~/mysite && git pull

Option C — WinSCP / MobaXterm / FileZilla (SFTP): connect with host <PUBLIC_IP>, port 22, your user and private key, then drag and drop.

Deploying directly into the web root

You cannot scp directly into /var/www/... because it is owned by root. Either upload to your home folder and sudo cp (as shown below), or make your login user the owner of the site folder once: sudo chown -R $USER:$USER /var/www/mysite. Files stay world-readable (644), so the web server can still read them.