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

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.

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.

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.