🌐 Host a Flask Website for Free with Google Cloud Shell + LocalTunnel
Ever wanted to host a website for free that the world can see—without deploying to AWS, Heroku, or paying for a server? Here's a clever trick using:
- ✅ Google Cloud Shell (comes with free CPU/memory)
- ✅ LocalTunnel (creates a public URL for your localhost)
- ✅ Flask (for the web app)
All of this runs remotely—you don’t need your own computer or IP to stay online.
📦 Step 1: Create Your Free GCP Cloud Shell Environment
Sign up at https://shell.cloud.google.com
Google Cloud gives you:
- A free Linux container that runs even if your browser is closed
- 5GB persistent disk
- 1 vCPU and 1.7GB RAM
🔐 Step 2: Authenticate and Fetch LocalTunnel Secrets (Optional)
gcloud cloud-shell ssh --authorize-session --command 'wget -q -O - https://loca.lt/mytunnelpassword && echo ""'
This silently pulls your tunnel password or configuration using wget.
🌐 Step 3: Install LocalTunnel and Start a Public Tunnel
gcloud cloud-shell ssh --authorize-session --command 'sudo apt-get install nodejs npm -y; sudo npm install -g localtunnel && lt --port 8000 --subdomain awakened-coffers'
This:
- Installs Node.js and npm
- Globally installs LocalTunnel
- Exposes port 8000 at
https://{named_domain}.loca.lt
🐍 Step 4: Run Your Flask App on Port 8000
gcloud cloud-shell ssh --authorize-session --command '
echo "
from flask import Flask
app = Flask(__name__)
@app.route(\"/\")
def hello():
return \"Hello and welcome to {named domain}!\"
app.run(host=\"0.0.0.0\", port=8000)
" > app.py &&
python3 app.py && rm app.py && sudo kill 1'
This command:
- Writes the Flask app to
app.py - Runs it on
0.0.0.0:8000 - Cleans up the file and stops the shell when finished
✅ Result: Your Website Is Live!
Visit: https://{named_domain}.loca.lt
You’ll see:
Hello and welcome to {named_domain}!
🧠 Final Notes
- Cloud Shell stops after 1 hour of inactivity
- the most effective way to keep a website running for free is rerunning on the hour
- if needed, relocate point of execution of the website
- And lastly, always load off of github.
- You now have a truly freely computed in the cloud website..
Happy hacking! 🚀