Chapter 10: Dynamic Website Hosting (PHP, Python, Node.js with MySQL)
Interview Questions
- Q1. What is PHP-FPM?
- FastCGI Process Manager — a separate service that runs PHP worker processes; Nginx (or Apache) passes .php requests to it over a unix socket or TCP.
- Q2. Why do we run Gunicorn in front of a Flask app?
- Flask's built-in server is for development only. Gunicorn is a production WSGI server that runs multiple worker processes reliably; Nginx sits in front for TLS and static files.
- Q3. What is pm2 used for?
- A process manager for Node.js that keeps apps running, restarts them on crash, starts them at boot (
pm2 startup+pm2 save), manages logs and supports cluster mode. - Q4. Why should the database never be exposed to the internet?
- Open database ports are scanned and attacked constantly (brute force, ransomware). The DB should listen on localhost or a private subnet and allow access only from the app's security group.
- Q5. How do you create a MySQL user with access to only one database?
CREATE USER 'app'@'localhost' IDENTIFIED BY '...'; GRANT ALL PRIVILEGES ON appdb.* TO 'app'@'localhost'; FLUSH PRIVILEGES;- Q6. What causes a 502 Bad Gateway error behind Nginx?
- The upstream is unreachable: app not running, wrong port/socket in
proxy_pass/fastcgi_pass, app crashed, or SELinux blocking the connection. - Q7. How do you run an application as a service on Linux?
- Create a systemd unit file in
/etc/systemd/system/, thensudo systemctl daemon-reload,sudo service <name> startandsudo systemctl enable <name>.