Accessing the website - "Error establishing a database connection" + WordPress Print

  • 0

Client query:
===================================================================================

when loading the website getting "Error establishing a database connection" Error

===================================================================================

Way of solution:

 

1) Check Your WordPress Database Credentials

- WordPress needs the following information for connecting to the database:

  • Database name
  • Database username
  • Database password
  • Database server

- This information is stored in your WordPress configuration file called "wp-config.php".

# vi /home/<user-name>/public_html/wp-config.php

- You’ll be looking for the following lines in the wp-config.php file.

~~~

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME''database_name_here' );
/** MySQL database username */
define( 'DB_USER''username_here' );
/** MySQL database password */
define( 'DB_PASSWORD''password_here' );
/** MySQL hostname */
define( 'DB_HOST''localhost' );
 

~~~

- You need to make sure that the information for the database name, username, password, and database host is correct. 

2) Check the user User Privileges

- Login into your hosting account and click on MySQL databases under the database section.

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

  • Select the user-name under the "user Privileges" and allow all Privileges to this user for connecting to the databse.

3) CageFS 

If there exists CageFs in the Server. Follow the below points.

-You can find the CageFs in the WHM. Kindly Login to WHM-->Search for CageFs

  • Find the domain or UserName in the CageFS.
  • If the domain or UserName exists in the CageFs.
  • Try removing from CageFs and check the website.
  • Add the Domain or UserName back to the CageFs. (Roshan Murugan)  

 

4) Check the error log for the domain:

# tailf /home/aerogear/public_html/error_log

# tailf /usr/local/apache/error_log

# tailf /usr/local/apache/log/error_log


Example error:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[15-Jun-2021 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
[15-Jun-2021 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
[15-Jun-2021 20:47:35 UTC] PHP Warning: Module 'PDO' already loaded in Unknown on line 0
[15-Jun-2021 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.

Step 1: Log in to your cPanel account.

Step 2: Look for the option “Select PHP Version” & click on it.

Step 3: Once there, change the PHP version to Current from the dropdown as shown below.

Step 4: 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.

 

5) You will need to enable and install the MySQL PHP extension using the EasyApache 4 interface in your WHM.

Step 1: Log into your WHM as root.

Step 2: Search for the option “EasyApache 4” & click on it.

Step 3: You will see a highlighted box “Currently Installed Packages”, click on the ‘customize’ button.

Step 4: Once there, select ‘PHP Extensions’ and in the search box type mysql, you will see the mysqlnd options.

Step 5: Select the required mysqlnd extension as per your requirement of the PHP versions. You can simply select all the version that are displayed, this will cause no problems.

Step 6: Once you have select the mysqlnd extensions there click on “Review”, scroll down and click on “Provision” button.

Step 7: 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:

# php -m

===================================================================================


Was this answer helpful?

« Back