Error establishing a database connection - Lightsail & Wordpress

0

Hi all,

I'm new to AWS and decided to start the project of migrating my website to AWS Lightsail. I followed all the steps on the process suggested by Amazon, however after 2 days, my site is still offline and the following message appeared yesterday night:

  • Error establishing a database connection (this happens when I enter my site cuentaovejaszzz.com)
  • Error establishing a database connection This either means that the username and password information in your wp-config.php file is incorrect or that contact with the database server at 127.0.0.1:3306 could not be established. This could mean your host’s database server is down. (this message appears when I enter using the static IP/wp-admin)*

I already restored the backup file of my old site into the new WP dashboard, but now I can't enter to it. I checked the wp-config.php since read that this may be a user/password issue, but I changed the hash password to the one provided on the Bitnami console, however still the issue persists.

Please any advice on how to overcome this issue will be highly appreciated.

Thanks in advance

WP-CONFIG.PHP file code `<?php //Begin Really Simple SSL session cookie settings @ini_set('session.cookie_httponly', true); @ini_set('session.cookie_secure', true); @ini_set('session.use_only_cookies', true); //END Really Simple SSL cookie settings

define( 'WP_CACHE', true ); // Added by WP Rocket

*/

// ** Database settings - You can get this info from your web host ** //

/** The name of the database for WordPress */

define( 'DB_NAME', 'bitnami_wordpress' );

/** Database username */

define( 'DB_USER', 'bn_wordpress' );

/** Database password */

define( 'DB_PASSWORD', 'PRIVATE INFO' );

/** Database hostname */

define( 'DB_HOST', '127.0.0.1:3306' );

/** Database charset to use in creating database tables. */

define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */

define( 'DB_COLLATE', '' );

/**#@+

  • Authentication unique keys and salts.

  • Change these to different unique phrases! You can generate these using

  • the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.

  • You can change these at any point in time to invalidate all existing cookies.

  • This will force all users to have to log in again.

  • @since 2.6.0

*/

define( 'AUTH_KEY', 'PRIVATE INFO' );

define( 'SECURE_AUTH_KEY', 'PRIVATE INFO' );

define( 'LOGGED_IN_KEY', 'PRIVATE INFO' );

define( 'NONCE_KEY', 'PRIVATE INFO );

define( 'AUTH_SALT', 'yb/::Q:tQA{}YPcX6E$rv!B?A _c8.Hs` az-]fFz@b}u^][tSc@FTSCz^tQ*I' );

define( 'SECURE_AUTH_SALT', 'PRIVATE INFO' );

define( 'LOGGED_IN_SALT', 'PRIVATE INFO' );

define( 'NONCE_SALT', 'PRIVATE INFO' );

/**#@-*/

/**

  • WordPress database table prefix.

  • You can have multiple installations in one database if you give each

  • a unique prefix. Only numbers, letters, and underscores please!

*/

$table_prefix = 'wp_';

/**

  • For developers: WordPress debugging mode.

  • Change this to true to enable the display of notices during development.

  • It is strongly recommended that plugin and theme developers use WP_DEBUG

  • in their development environments.

  • For information on other constants that can be used for debugging,

  • visit the documentation.

  • @link https://wordpress.org/documentation/article/debugging-in-wordpress/

*/

define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */

define( 'FS_METHOD', 'direct' ); /**

  • The WP_SITEURL and WP_HOME options are configured to access from any hostname or IP address.
  • If you want to access only from an specific domain, you can modify them. For example:
  • define('WP_HOME','http://example.com');
  • define('WP_SITEURL','http://example.com');

*/ if ( defined( 'WP_CLI' ) ) { $_SERVER['HTTP_HOST'] = '127.0.0.1'; }

define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); define( 'WP_AUTO_UPDATE_CORE', 'minor' ); /* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */

if ( ! defined( 'ABSPATH' ) ) {

define( 'ABSPATH', __DIR__ . '/' );

}

/** Sets up WordPress vars and included files. */

require_once ABSPATH . 'wp-settings.php';

/**

  • Disable pingback.ping xmlrpc method to prevent WordPress from participating in DDoS attacks
  • More info at: https://docs.bitnami.com/general/apps/wordpress/troubleshooting/xmlrpc-and-pingback/ */ if ( !defined( 'WP_CLI' ) ) { // remove x-pingback HTTP header add_filter("wp_headers", function($headers) { unset($headers["X-Pingback"]); return $headers; }); // disable pingbacks add_filter( "xmlrpc_methods", function( $methods ) { unset( $methods["pingback.ping"] ); return $methods; }); } `
5 Answers
0

As you can see in the error, is the database you are using down?
Can I login directly to the database using the database password set in wp-config.php?
Where are you running your database?
If you have a database outside of Lightsail you will need to change the "DB_HOST" value.

profile picture
EXPERT
answered a year ago
  • Hi Riku, thanks for your reply. "is the database you are using down?" I suspect the DB is down, I'm newbie on this and as far as I could google by the error message, I can't restart MySQL or MariaDB, I get other error messages on Bitnami. "Can I login directly to the database using the database password set in wp-config.php?" I didn't post the password in my question, if needed I can send it to you by PM. "Where are you running your database?" I only setup the instance and then moved my old site using All-in-one migration plugin. On the Lightsail console I'm running the WP instance, static IP, a DNS service and the CDN service, nothing else like containers. "If you have a database outside of Lightsail you will need to change the "DB_HOST" value." As far as I understand, the DB should be inside Lightsail.

  • If the database is running within Lightsail, you need to make sure the database is up and running. Make an SSH connection to Lightsail and start MySQL or MariaDB.
    The following Bitnami documentation shows a command to restart each service at once, so please execute this command. https://docs.bitnami.com/google/infrastructure/mariadb/administration/control-services/

    sudo /opt/bitnami/ctlscript.sh restart
    
  • Hi Riku, I entered the restart comand and got this error: A Job for bitnami.service failed because the control process exited with error code. See "systemctl status bitnami.service" and "journalctl -xe" for details.

    I also ran this "systemctl status bitnami.service" and got:

    ● bitnami.service - LSB: bitnami init script Loaded: loaded (/etc/init.d/bitnami; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2023-06-01 14:28:04 UTC; 3min 13s ago Process: 12340 ExecStart=/etc/init.d/bitnami start (code=exited, status=1/FAILURE) Tasks: 22 (limit: 2353) Memory: 184.5M CPU: 1.707s CGroup: /system.slice/bitnami.service

0

Hello,

Did you lose DB access before or after you "changed the hash password to the one provided on the Bitnami console?" Based on the above, it looks like you did not explicitly setup a DB correct, meaning you are using the default one local to the same instance running WordPress?

It's possible that you've changed the password to an incorrect one.

On the other hand, if everything worked and then stopped working without any manual changes, it is possible you are overloading your instance with traffic. You can look at bursting capacity vs. load per this guide: https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-viewing-instance-burst-capacity.

Based on the above description, it sounds more likely that the password has been changed to the wrong value, but please provide any info you can to clarify the steps leading up to the DB failures.

-Andy

AWS
MODERATOR
answered 10 months ago
  • I have the same issue for the past 5 days and tried to find the cause but I was unable to do so. Website traffic was per day average of 10 users. My website was under malware attack (Japanese keywords snippet) and It was removed from the website. However, after a few days, the site started to show a database error. I have tried to restart MariaDB but I could not. This was the command and result. bitnami@ip-###-##-##-##:~$ sudo /opt/bitnami/ctlscript.sh status mariadb Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (/var/run/gonit.pid)

0

Hi Riku, thanks for your reply.

  • "is the database you are using down?" I suspect the DB is down, I'm newbie on this and as far as I could google by the error message, I can't restart MySQL or MariaDB, I get other error messages on Bitnami.
  • "Can I login directly to the database using the database password set in wp-config.php?" I didn't post the password in my question, if needed I can send it to you by PM.
  • "Where are you running your database?" I only setup the instance and then moved my old site using All-in-one migration plugin. On the Lightsail console I'm running the WP instance, static IP, a DNS service and the CDN service, nothing else like containers.
  • "If you have a database outside of Lightsail you will need to change the "DB_HOST" value." As far as I understand, the DB should be inside Lightsail.

Hope this can give you further info on my issue. KR

answered a year ago
0

I have the same issue for the past 5 days and tried to find the cause but I was unable to do so. Website traffic was per day average of 10 users. My website was under malware attack (Japanese keywords snippet) and It was removed from the website. However, after a few days, the site started to show a database error. I have tried to restart MariaDB but I could not. This was the command and result. bitnami@ip-###-##-##-##:~$ sudo /opt/bitnami/ctlscript.sh status mariadb Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (/var/run/gonit.pid)

answered 6 months ago
0

same issues here. To try to fix this, I created multiple instances with different snapshots of the last 7 days, seems like the one from 7 days ago works, but not the rest of them, I compared the password in config file and they all have the same password

answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions