How to fix a 500 Internal Server Error and find the real cause

A 500 error (Internal Server Error) means the server received the request but your code hit a problem handling it. The message deliberately says nothing specific, because error details could expose sensitive information to strangers. So the real cause is always in the logs, not on the error page.
How a 500 differs from other errors
| Code | Meaning | Where to look |
|---|---|---|
| 500 | The code hit a problem | Application logs |
| 502 | The application is down | Startup logs, the port |
| 503 | Overloaded or temporarily off | Resources, site status |
| 504 | The application took too long | Slow queries, external APIs |
| 404 | Page not found | The path, route settings |
How to find the error

1. Read the logs as the error happens
Reload the failing page and read the application logs. On VibeVN they are on the site's detail page. Look for a stack trace. The first line usually gives the error type and the file.
2. Narrow it down
- Every page fails: usually configuration, environment variables or the database.
- Only one page fails: that page's code or data.
- It began after a deployment: compare with the previous version. On VibeVN you can roll back to get the site running, then look for the bug.
- It comes and goes: think overload, exhausted database connections or a flaky external API.
3. Fix it and test again
After fixing, repeat the exact action that caused the error. If you ask an AI for help, paste the stack trace itself rather than saying "my site has a 500 error".
Common causes
Missing or wrong environment variables
The most common cause on a newly deployed site. Your machine has an .env file and the server does not. Compare .env.example with the settings on the server.
No database connection
Search the logs for ECONNREFUSED, P1001, password authentication failed or SQLSTATE. A connection string pointing at localhost is a typical slip when moving from your machine to a server.
Migrations have not run
The site runs but the tables do not exist: relation "users" does not exist or SQLSTATE[42S02]. Run the migrations and it is solved.
Unhandled errors in the code
Often seen in AI-written code that assumes data is always there:
// Crashes if the user does not exist
const name = user.profile.name;
// Safer
const name = user?.profile?.name ?? "Guest";
Wrap API and database calls in try/catch, return a clear message and log the details.
An external API failing or expired
An OpenAI key out of credit, or a payment API whose settings changed. Without error handling, an outside problem becomes a 500 on your site.
No permission to write a file
The code writes to a folder that is forbidden or missing. On VibeVN, write to /app/data.
A 500 error by technology
Next.js. The page shows Application error: a server-side exception has occurred, and the real content is in the server log. Typical causes are calling localhost on the server side, missing environment variables, or next-auth lacking its URL and secret.
Node.js and Express. An uncaught error in an async function can hang the request or crash the process. Add error handling middleware. See Node.js hosting.
Laravel and PHP. With APP_DEBUG=false, the error page shows no details, so read the logs. Common cases are listed in cheap PHP hosting for Laravel. Do not leave APP_DEBUG=true on a live site, because it can show passwords on the error page.
WordPress. Usually a plugin or .htaccess. Rename the plugins folder to switch them off temporarily, or turn on logging with WP_DEBUG_LOG.
If it has never worked
If the site has never run successfully, you may have a build or startup error rather than a 500. Read fixing Next.js build errors.
Frequently asked questions
Does a 500 error hurt SEO?
A brief error has little effect, but if it lasts, Google crawls less often and may drop pages from its results. Deal with it early.
Can a visitor fix a 500 error?
No. Reloading only helps if the error was temporary. The fix is up to whoever runs the site.


