Ravindra BagaleCourses & study guides

9. PHP, LAMP and LEMP Step by Step

9.1 Static vs Dynamic and How PHP Runs

Static site madhe server fakt file uchalun deto. Dynamic site madhe server aadhi code chalavto (PHP), code database la vicharto, aani mag tayar zalela HTML pathavto.

 Static:   Browser --GET /about.html--> Nginx --reads file--> same HTML for everyone

 Dynamic:  Browser --GET /feed.php--> Nginx --FastCGI--> PHP-FPM --SQL--> MySQL
                                                           |
                               HTML built for THIS user <--+
Way to run PHP Used with How it works
mod_php Apache (common on Ubuntu) PHP is loaded inside every Apache process
PHP-FPM Nginx (always), Apache on Amazon Linux Separate pool of PHP worker processes; web server talks to it over a unix socket (FastCGI)

Why this matters for security

Dynamic code is where most serious web vulnerabilities live – SQL injection, XSS, file upload, command injection (Part 11). A static site has very little to attack; a PHP app that talks to a database has a lot. That is why we build one ourselves before we attack one.

Ravindra Bagale's Tip

Many students think PHP runs in the browser. No! PHP runs on the server, and the browser only receives HTML – that's why you can't see PHP code in "View Source". If PHP code shows up in the browser, the server isn't running PHP – that's a configuration mistake.

Practice task

Draw the request flow for a static page and for a PHP page, labelling the port or socket at each arrow.