Chapter 10: Dynamic Website Hosting (PHP, Python, Node.js with MySQL)
Practice Questions and Lab Exercises
- Draw the 3-tier architecture of a dynamic website on a single EC2 instance.
- What is PHP-FPM? How does Nginx communicate with it?
- Why should the app listen on
127.0.0.1and not0.0.0.0? - Write SQL to create a database
college, a userwebwith password, and grant all privileges on that database only. - What is the purpose of Gunicorn? Of pm2?
- Explain each line of the Flask systemd unit file.
- What causes 502 Bad Gateway? Give three checks.
- Lab: Deploy the PHP app on Ubuntu + Nginx, add three students via the form and verify the rows in MySQL.
- Lab: Deploy the Flask app on Amazon Linux 2023 behind Nginx with a systemd service; reboot the instance and confirm the app starts automatically.
- Lab: Deploy the Node app on CentOS Stream 9 with pm2 behind Nginx. Observe the 502 error before running
setsebooland after.
Quick Revision
- Dynamic = code + DB. Web server → app server → database.
- DB: AL2023
mariadb105-server, Ubuntumysql-server, CentOSmariadb-server;mysql_secure_installation; create dedicated user; never open 3306. - PHP: PHP-FPM socket (
/run/php-fpm/www.sockor/run/php/php8.x-fpm.sock); Apache on Ubuntu useslibapache2-mod-php. - Python: venv + Flask + PyMySQL + Gunicorn under systemd on
127.0.0.1:5000. - Node: NodeSource LTS + Express + mysql2; pm2 (
start,startup,save) or systemd on127.0.0.1:3000. - Reverse proxy: Nginx
proxy_pass, ApacheProxyPass; on CentOSsetsebool -P httpd_can_network_connect 1.