Chapter 10: Dynamic Website Hosting (PHP, Python, Node.js with MySQL)
10.1 Why and what
Friends, static sites are nice, but real applications need logins, forms and data. If Mauli Dairy wants to save customer orders, it needs both code and a database. Let's first understand what changes when a site becomes dynamic.
मित्रांनो, स्टॅटिक साइट्स छान आहेत, पण खऱ्या ॲप्लिकेशन्सना लॉगिन, फॉर्म्स आणि डेटा लागतो. Mauli Dairy ला कस्टमर ऑर्डर्स सेव्ह करायच्या असतील तर कोड आणि डेटाबेस दोन्ही लागतात. आधी समजून घेऊ की साइट डायनॅमिक झाल्यावर काय बदलतं.
दोस्तों, स्टैटिक साइट्स अच्छी हैं, पर असली ऐप्लिकेशन्स को लॉगिन, फ़ॉर्म्स और डेटा चाहिए. Mauli Dairy को कस्टमर ऑर्डर्स सेव करने हों तो कोड और डेटाबेस दोनों चाहिए. पहले समझते हैं कि साइट डायनामिक होने पर क्या बदलता है.
A dynamic website generates pages at request time using server-side code and usually a database — login systems, e-commerce, result portals, blogs. The page for user A can differ from the page for user B.
3-tier architecture on a single EC2 instance
Browser ──HTTP:80──► [ Web tier ] Nginx / Apache (reverse proxy, static files)
│
▼ FastCGI socket / HTTP 127.0.0.1:3000 or :5000
[ App tier ] PHP-FPM | Gunicorn + Flask | Node + Express
│
▼ TCP 127.0.0.1:3306 or unix socket
[ Data tier ] MySQL / MariaDB (never exposed to the internet)
| Language | App server / runtime | How the web server talks to it | Process manager |
|---|---|---|---|
| PHP | PHP-FPM (FastCGI Process Manager) or Apache mod_php |
FastCGI over a unix socket | systemd (php-fpm / php8.x-fpm) |
| Python (Flask/Django) | Gunicorn (WSGI server) | HTTP reverse proxy to 127.0.0.1:5000 |
systemd unit |
| Node.js (Express) | Node itself | HTTP reverse proxy to 127.0.0.1:3000 |
pm2 or systemd unit |
Why a reverse proxy?
App servers are good at running code but not at handling slow clients, TLS, compression, static files and security headers. Nginx/Apache in front does that job, lets you use port 80/443 without running your app as root, and lets many apps share one server.
Ravindra Bagale's Tip
Many students run the app on 0.0.0.0 and open 3000 or 5000 in the security group. Always keep the app on 127.0.0.1, and expose only Nginx/Apache on port 80/443. And never expose the database – it is the last tier.
Ravindra Bagale's Tip – मराठी
खूप students app 0.0.0.0 वर चालवतात आणि security group मध्ये 3000 किंवा 5000 open करतात. App नेहमी 127.0.0.1 वर ठेवा आणि बाहेर फक्त Nginx/Apache port 80/443 वर. Database तर कधीच बाहेर नको – तो शेवटचा tier आहे.
Ravindra Bagale's Tip – हिंदी
बहुत students app 0.0.0.0 पर चलाते हैं और security group में 3000 या 5000 open कर देते हैं. App हमेशा 127.0.0.1 पर रखो और बाहर सिर्फ़ Nginx/Apache port 80/443 पर. Database तो कभी बाहर नहीं – वो आखिरी tier है.
Lab
Chala, Mauli Dairy chya order system sathi kagdavar teen tiers kadha: web, app aani data. Pratyek tier samor software (udaharan Nginx, Gunicorn, MariaDB), port aani te internet la disel ki nahi te liha.