Error Establishing a Database Connection in WordPress – Cpanel Server
In this blog, we will show you the steps to resolve the Error Establishing a Database Connection in WordPress – Cpanel Server
The domain is hosted in the Cpanel server and faced the below-mentioned database error. By following our suggested solutions, we may resolve the database connection problems.

Step 1:-
- Login to the SSH goes to the Cpanel domain document path ” /home/<user-name>/public_html/”
- Open the wp-config.php and check your WordPress database credentials
– WordPress needs the following information for connecting to the database:

- Database name
- Database username
- Database password
- Database server
You need to make sure that the information for the database name, username, password, and database host is correct.
Step 2:-
Check the user User Privileges
- Login into your Cpanel hosting account

- Click on MySQL databases under the database section.

- This will take you to the Cpanel database management page in your hosting dashboard. From here, you can find out your database name and username.

- Select the user name and database name under the “User To Database” Press “Add” It will redirect to screen 2.

- You can select the check box ALL PRIVILEGES and click the button Make Changes. It will assign the database privileges to all the databases.

https://docs.cpanel.net/whm/sql-services/manage-mysql-profiles/88/
Step 3:
We had an experience with CloudLinux & CageFs, there is yet another way to fix the Cpanel server’s database connectivity issue. Please do the following.
- You can find the CageFs in the WHM by Searching for CageFs

- Find the domain or UserName in the CageFS.

- If the domain or UserName exists in the CageFs then try removing it from CageFs and check the website.

- Add the Domain or UserName back to the CageFs.

step 4:
On troubleshooting the log related to Cpanel WordPress database connectivity. You can check the logs the error log for the domain:
# tailf /home/username/public_html/error_log

# tailf /usr/local/apache/error_log

# tailf /usr/local/apache/log/error_log
Here is a sample error that we have faced during troubleshooting: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [20:47:35 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '/opt/cpanel/ea-php56/root/usr/lib64/php/modules/pdo_mysql.so' - /opt/cpanel/ea-php56/root/usr/lib64/php/modules/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0 [20:47:35 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '/opt/cpanel/ea-php56/root/usr/lib64/php/modules/sqlite.so' - /opt/cpanel/ea-php56/root/usr/lib64/php/modules/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0 [ 20:47:35 UTC] PHP Warning: Module 'PDO' already loaded in Unknown on line 0 [ 20:47:35 UTC] PHP Warning: Module 'pdo_sqlite' already loaded in Unknown on line 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note: This error is caused by the MySQL extension being disabled on your hosting account. In order to enable it, please do the following steps.
- Log in to your cPanel account.
- Look for the option “Select PHP Version” & click on it.
- Once there, change the PHP version to Current from the dropdown as shown below.
- Once you have selected the PHP version as current, tick on the option that says pdo, pdo_sqlite, SQLite, pdo_mysql, “mysqli” and/or “mysqlnd” from the options presented and click save.
Step 5:
You will need to enable and install the MySQL PHP extension using the EasyApache 4 interface in your WHM.
- Log into your WHM as root.
- Search for the option “EasyApache 4” & click on it.
- You will see a highlighted box “Currently Installed Packages”, click on the ‘customize’ button.
- Once there, select ‘PHP Extensions’ and in the search box type MySQL, you will see the mysqlnd options.
- Select the required mysqlnd extension as per your requirement of the PHP versions. You can simply select all the version that is displayed, this will cause no problems.
- Once you have selected the mysqlnd extensions there click on “Review”, scroll down and click on the “Provision” button.
- Once finished, click on done and check your WordPress installation and the error should be gone.
– To check the modules are installed on the server you can use below command
# php -m