Okay, let’s be real—seeing a 500 Internal Server Error can feel like your site just slammed the door in your face. But don’t freak out. When that error is a database connection error, it’s usually something you can fix with a few quick steps.
Below we’ve outlined the most common fixes—wrong password, crashed MySQL server, tiny typo in your config file. Follow along and you’ll have your site back up in no time.
1. Check Your Database Settings
Let’s get started. Open your site’s config file:
- WordPress → wp-config.php
- Laravel → .env file
- Custom PHP → Your database connection script
Make sure everything is correct:
php
- define(‘DB_NAME’, ‘your_db_name’);
- define(‘DB_USER’, ‘your_db_user’);
- define(‘DB_PASSWORD’, ‘your_db_password’);
- define(‘DB_HOST’, ‘localhost’);
One mistake here and you’re stuck.
2. Test the Database Manually
Open your terminal and try to login:
bash
mysql -u your_db_user -p
If this fails, your password or user is wrong—or the database server isn’t running.
3. Restart Your Database Server
Sometimes a simple reboot fixes everything.
Linux:
bash
sudo systemctl restart mysql
Windows/XAMPP:
Just stop and start MySQL from the XAMPP control panel. If MySQL crashed or froze, this will bring it back to life.
4. Fix File Permissions (Linux Users)
Your server might be unable to read config files.
bash
sudo chown -R www-data:www-data /var/www/html sudo chmod 644 /var/www/html/wp-config.php
This lets the web server access your files.
5. Check the PHP & Server Error Logs
Logs are your best friend. Look for:
- Apache → /var/log/apache2/error.log
- Nginx → /var/log/nginx/error.log
- PHP → php_error.log
Search for lines with words like “connect”, “denied”, or “timeout”.
1. WordPress
- Clear cache plugins
- Disable plugins/themes via FTP and test again
- Enable debugging in wp-config.php:
php
define(‘WP_DEBUG’, true);
2. Laravel
Run:
bash
php artisan config:clear
Check .env variables match your MySQL credentials
3. Custom PHP
Make sure mysqli_connect() or PDO is used correctly
Add error handlers like:
php
mysqli_connect() or die(“Database not connected: ” . mysqli_connect_error());
Leave a Reply