Ravindra BagaleCourses & study guides मराठी Track your progress

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

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

Friends, the sample site is fine, but in a real project you have to take the files from your laptop to the server. There are three ways – scp, git clone and SFTP tools. Use whichever feels easiest.

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.

Ravindra Bagale's Tip

Many students run scp on the server instead of the laptop, or get the key path wrong. scp always runs from the laptop, and upload into your home folder – not straight into /var/www. If you use WinSCP or MobaXterm on Windows, give port 22 and the .pem/.ppk key.

Lab

Chala, tumchya laptop var ek chhota mysite folder banva aani scp -i mykey.pem -r ./mysite ec2-user@<PUBLIC_IP>:~/ ne upload kara. Server var ls ~/mysite ne files aalya ka te bagha.