Chapter 10: Dynamic Website Hosting (PHP, Python, Node.js with MySQL)
10.7 Troubleshooting dynamic sites
Friends, a dynamic site has three tiers, so the problem can be in three places. Use this table: first the app, then the database, then the web server.
मित्रांनो, डायनॅमिक साइटमध्ये तीन टियर्स, म्हणजे प्रॉब्लेम तीन जागी असू शकतो. हा टेबल वापरा: आधी ॲप, मग डेटाबेस, मग वेब सर्व्हर.
दोस्तों, डायनामिक साइट में तीन टियर्स, मतलब प्रॉब्लम तीन जगह हो सकता है. ये टेबल इस्तेमाल करो: पहले ऐप, फिर डेटाबेस, फिर वेब सर्वर.
| Symptom | Cause | Fix |
|---|---|---|
| 502 Bad Gateway | App not running; wrong port/socket; SELinux blocks proxy | sudo service flaskapp status/pm2 status; curl 127.0.0.1:3000; setsebool -P httpd_can_network_connect 1 |
| 504 Gateway Timeout | App too slow / stuck on DB | Check app logs; DB running? |
Access denied for user 'appuser' |
Wrong password or host (localhost vs 127.0.0.1) |
SELECT user,host FROM mysql.user; recreate user |
ECONNREFUSED ::1:3306 (Node) |
localhost resolved to IPv6 |
Use DB_HOST=127.0.0.1 |
Can't connect to MySQL server |
MariaDB/MySQL stopped | sudo service mariadb start (or mysql) |
cryptography package is required (Python) |
MySQL 8 auth needs it | pip install cryptography |
| PHP shown as text / downloaded | PHP handler missing | Install/start php-fpm; check location ~ \.php$ |
| Blank page / 500 in PHP | PHP error | sudo tail /var/log/php-fpm/www-error.log (AL/CentOS) or Nginx/Apache error log |
systemd service status=203/EXEC |
Wrong path in ExecStart, or SELinux blocking a binary in a home folder |
Check path; keep apps in /opt |
Ravindra Bagale's Tip
When an error comes up, check three things in order: the app's log (journalctl -u flaskapp or pm2 logs), the database status (sudo service mariadb status), and finally the Nginx error log. Most of the time the answer is in the very first log.
Ravindra Bagale's Tip – मराठी
Error आला की तीन गोष्टी क्रमाने बघा: app चा log (journalctl -u flaskapp किंवा pm2 logs), database चा status (sudo service mariadb status), आणि शेवटी Nginx चा error log. बहुतेक वेळा पहिल्याच log मध्ये उत्तर मिळतं.
Ravindra Bagale's Tip – हिंदी
Error आए तो तीन चीज़ें क्रम से देखो: app का log (journalctl -u flaskapp या pm2 logs), database का status (sudo service mariadb status), और आखिर में Nginx का error log. ज़्यादातर बार पहले ही log में जवाब मिल जाता है.
Lab
Chala, .env madhe DB_PASS muddam chukicha kara, sudo service flaskapp restart kara aani curl -s http://127.0.0.1:5000/api/students kaay dakhavto te liha. journalctl -u flaskapp -n 20 madhe error shodha, table madhun fix olkha, aani password parat barobar kara.
A simple order for checking
- Is the app running? Check
systemctl statusorpm2 status. - Does the app answer locally? Try
curl 127.0.0.1:PORT. - Can the app reach the database? Read the app log.
- Does nginx point to the right port or socket? Run
nginx -T | grep proxy_pass. - Is SELinux blocking the proxy (CentOS)? Run
getsebool httpd_can_network_connect.
The same checks for other stacks
If your team uses a different language, these are the equivalents.
Java / Spring Boot
Check the app is up and connected to the database. The Actuator health endpoint shows both.
curl -s 127.0.0.1:8080/actuator/healthWhat you see:
{"status":"UP","components":{"db":{"status":"UP"}}}.NET / ASP.NET Core
Use a health-check endpoint, added with AddHealthChecks().
curl -s 127.0.0.1:5000/healthWhat you see:
HealthyPython / Django
Run the deploy checks and test the database connection.
python manage.py check --deploy && python manage.py dbshellWhat you see:
System check identified no issuesGo
A simple /healthz handler that pings the database.
curl -s 127.0.0.1:8080/healthzWhat you see:
okPostgreSQL
Is it accepting connections?
pg_isready -h 127.0.0.1What you see:
127.0.0.1:5432 - accepting connectionsMongoDB
Ping from the shell.
mongosh --eval "db.runCommand({ping:1})"What you see:
{ ok: 1 }Redis
Does auth work?
redis-cli -a "$REDIS_PASS" PINGWhat you see:
PONGSummary
| Stack | Health check |
|---|---|
| Spring Boot | /actuator/health |
| ASP.NET Core | /health |
| Django | check --deploy |
| Go | /healthz |
| PostgreSQL | pg_isready |
| MongoDB | ping |
| Redis | PING |
Real examples
Indian company (sample): a Meesho-style app showed 502s after a deploy. The Node app crashed on start because DB_HOST was missing from the new server's environment. pm2 logs showed it in one line. Everyday: if a restaurant order is late, check the kitchen (app), then the pantry (database), then the waiter (nginx).
Recap
- App first, then the database, then the proxy.
- Health endpoints make checking easy in every stack.