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.
मित्रांनो, सॅम्पल साइट ठीक आहे, पण खऱ्या प्रोजेक्टमध्ये तुमच्या लॅपटॉपवरच्या फाइल्स सर्व्हरवर न्याव्या लागतात. तीन मार्ग आहेत – scp, git clone आणि SFTP टूल्स. तुम्हाला सोपा वाटेल तो वापरा.
दोस्तों, सैंपल साइट ठीक है, लेकिन असली प्रोजेक्ट में आपके लैपटॉप की फ़ाइलें सर्वर पर ले जानी पड़ती हैं. तीन तरीके हैं – scp, git clone और SFTP टूल्स. जो आसान लगे वो इस्तेमाल करो.
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.
Ravindra Bagale's Tip – मराठी
खूप students scp laptop ऐवजी server वर चालवतात, किंवा key path चुकवतात. scp नेहमी laptop वरून चालतं, आणि तुमच्या home folder मध्ये upload करा – थेट /var/www मध्ये नाही. Windows वर WinSCP किंवा MobaXterm वापरत असाल तर port 22 आणि .pem/.ppk key द्या.
Ravindra Bagale's Tip – हिंदी
बहुत students scp laptop की जगह server पर चलाते हैं, या key path गलत देते हैं. scp हमेशा laptop से चलता है, और अपने home folder में upload करो – सीधे /var/www में नहीं. Windows पर WinSCP या MobaXterm इस्तेमाल कर रहे हो तो port 22 और .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.