Ravindra BagaleCourses & study guides

Chapter 10: Dynamic Website Hosting (PHP, Python, Node.js with MySQL)

10.1 Why and what

Mitranno, static sites are nice, but real applications need logins, forms and data. 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.