Ravindra BagaleCourses & study guides मराठी Track your progress

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.

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

  1. Is the app running? Check systemctl status or pm2 status.
  2. Does the app answer locally? Try curl 127.0.0.1:PORT.
  3. Can the app reach the database? Read the app log.
  4. Does nginx point to the right port or socket? Run nginx -T | grep proxy_pass.
  5. 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/health

What 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/health

What you see:

Healthy
Python / Django

Run the deploy checks and test the database connection.

python manage.py check --deploy && python manage.py dbshell

What you see:

System check identified no issues
Go

A simple /healthz handler that pings the database.

curl -s 127.0.0.1:8080/healthz

What you see:

ok
PostgreSQL

Is it accepting connections?

pg_isready -h 127.0.0.1

What you see:

127.0.0.1:5432 - accepting connections
MongoDB

Ping from the shell.

mongosh --eval "db.runCommand({ping:1})"

What you see:

{ ok: 1 }
Redis

Does auth work?

redis-cli -a "$REDIS_PASS" PING

What you see:

PONG

Summary

StackHealth check
Spring Boot/actuator/health
ASP.NET Core/health
Djangocheck --deploy
Go/healthz
PostgreSQLpg_isready
MongoDBping
RedisPING

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.