-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.txt
More file actions
64 lines (36 loc) Β· 1.4 KB
/
python.txt
File metadata and controls
64 lines (36 loc) Β· 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
π python-server-setup.txt
# Python HTTP Server Setup Guide
python3 -m http.server 8000 --bind 0.0.0.0
This file provides instructions to start a basic web server using Python on an EC2 instance.
π Requirements:
- Python 3 installed (Amazon Linux 2, Ubuntu, etc.)
- EC2 instance with port 8000 or 8080 open in security group
- Basic HTML file (e.g., index.html) placed in your working directory
---
π§ Step 1: Connect to the EC2 instance via SSH
```bash
ssh -i "your-key.pem" ubuntu@<your-ec2-public-ip>
π§ Step 2: Update and install Python if not already available
sudo apt update
sudo apt install -y python3
Check version:
python3 --version
π§ Step 3: Move to the directory with your index.html file
cd /home/ubuntu/
π§ Step 4: Start the web server on port 8000
python3 -m http.server 8000 --bind 0.0.0.0
π This will serve files in the current directory over HTTP.
π Step 5: Visit your site in a browser
http://<your-ec2-public-ip>:8000
Make sure your EC2 security group allows inbound TCP traffic on port 8000.
π To stop the server, press:
CTRL + C
β
Example Output:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
π Optional: Run as background process
nohup python3 -m http.server 8000 --bind 0.0.0.0 &
This keeps it running after you log out.
π Note:
This server is not production-ready. It's great for:
Testing HTML files
Internal network demos