Synology: Error establishing a database connection after WordPress Import

Synology Error establishing a database connection After WordPress Import

You have imported your website from a private hosting service directly to your own Synology NAS but now, every time you try to access your website, you get this error: “Error establishing a database connection”.

synology error establishing a database connection solved

If the password and username in your wp-config.php file match perfectly and all the file permissions are set up correctly, the only remaining cause for this error is a wrong configuration of the folders inside the main WEB folder. If before importing your site from a private hosting to your own Synology NAS you already had a “WEB” folder with the folders called “WordPress” and “phpMyAdmin” inside, then you just have to insert the folder “yourwebsitename” directly in the main WordPress folder which was previously created automatically with the first installation of the official WordPress package from Synology. Only this way will it be recognized by WordPress and the “Error establishing a database connection” error will disappear.

Another possible cause for this error can be that the username and password in the .htaccess file and the wp-config file do not match. What to do in this case?

First of all Edit the .htaccess file like this:

# Synology PHP
AddHandler default-handler .htm .html .shtml
AddHandler php-fastcgi .php
AddType text/html .php
Action php-fastcgi /php56-fpm-handler.fcgi
# Synology PHP

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

After you do that, save it and overwrite the old .htaccess file. Remember to always make a backup of your .htaccess file before you edit or overwrite it.
Another solution is to open and edit the wp-config.php file, then go to DB_HOST and instead of ‘localhost’ set ‘localhost:/run/mysqld/mysqld10.sock’
Follow the instructions below:

/** MySQL hostname */
define('DB_HOST', 'localhost');
/** MySQL hostname */
define('DB_HOST', 'localhost:/run/mysqld/mysqld10.sock');

If the problem persists, do not hesitate to contact me by email.

This post was updated on Monday / August 9th, 2021 at 3:04 AM