Ravindra BagaleCourses & study guides

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

Practice Questions and Lab Exercises

  1. Draw the 3-tier architecture of a dynamic website on a single EC2 instance.
  2. What is PHP-FPM? How does Nginx communicate with it?
  3. Why should the app listen on 127.0.0.1 and not 0.0.0.0?
  4. Write SQL to create a database college, a user web with password, and grant all privileges on that database only.
  5. What is the purpose of Gunicorn? Of pm2?
  6. Explain each line of the Flask systemd unit file.
  7. What causes 502 Bad Gateway? Give three checks.
  8. Lab: Deploy the PHP app on Ubuntu + Nginx, add three students via the form and verify the rows in MySQL.
  9. Lab: Deploy the Flask app on Amazon Linux 2023 behind Nginx with a systemd service; reboot the instance and confirm the app starts automatically.
  10. Lab: Deploy the Node app on CentOS Stream 9 with pm2 behind Nginx. Observe the 502 error before running setsebool and after.

Quick Revision

  • Dynamic = code + DB. Web server → app server → database.
  • DB: AL2023 mariadb105-server, Ubuntu mysql-server, CentOS mariadb-server; mysql_secure_installation; create dedicated user; never open 3306.
  • PHP: PHP-FPM socket (/run/php-fpm/www.sock or /run/php/php8.x-fpm.sock); Apache on Ubuntu uses libapache2-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 on 127.0.0.1:3000.
  • Reverse proxy: Nginx proxy_pass, Apache ProxyPass; on CentOS setsebool -P httpd_can_network_connect 1.