cPanel Server Management
Error Establishing a Database Connection in WordPress – cPanel
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.
- 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.
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.
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.
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.
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
cPanel Server Management
Assistanz is a pioneer in offering 24×7 cPanel Server Management Service since 2004.
We offer 24×7 cPanel Server Management
- cPanel Server Management
- cPanel Installation and Setup
- cPanel Server Optimization
- cPanel Server Migration
- cPanel Server Security and Hardering
- cPanel Server Monitoring
- cPanel Server Hack Recovery
and Much more