• Resolved David

    (@digitalpurenetworks)


    NinjaFirewall fatal error : cannot retrieve WordPress database credentials. Please review your installation. Your site is not protected.

    I am getting this error suddenly in all my installs after I updated. No other changes were made. It was working fine previously, and the site is loading just fine. The status of the plugin says it is active also.

    Firewall Enabled
    PHP hook Enabled
    PHP SAPI – FPM-FCGI
    Engine version – 1.1.7
    Rules version – 20140212

    I would very much like to have this working. I have noticed a uptick in speed, and reliability of the site after installing your firewall. I have tried a few of the others, and while they are fun to play with not as useful as your firewall.

    https://www.ads-software.com/plugins/ninjafirewall/

Viewing 15 replies - 1 through 15 (of 28 total)
  • Plugin Author nintechnet

    (@nintechnet)

    Hi,

    What did you update: WordPress or NinjaFirewall ?
    This error means that the firewall was able to find, open and read the wp-config.php file, but not able to retreive all or one of the DB credentials (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, table_prefix) in it.

    Can you check your wp-config.php to see if there is anything unusual?

    Thread Starter David

    (@digitalpurenetworks)

    There is nothing in the wp-config that I can think of. I do not use any special settings. I only added the following, but removing these does not make any affect with your plugin. Everything else is standard wp-config-sample items.

    /* Custom WordPress URL. */
    define( ‘WP_SITEURL’, ‘https://www.’ );
    define( ‘WP_HOME’, ‘https://www.’ );

    /* Specify maximum number of Revisions. */
    define( ‘WP_POST_REVISIONS’, ‘3’ );
    /* Media Trash. */
    define( ‘MEDIA_TRASH’, true );

    /* Multisite. */
    define( ‘WP_ALLOW_MULTISITE’, false );

    /* PHP Memory */
    define( ‘WP_MAX_MEMORY_LIMIT’, ‘512M’ );

    /* WordPress Cache */
    define( ‘WP_CACHE’, true );

    /* Compression */
    define( ‘COMPRESS_CSS’, true );
    define( ‘COMPRESS_SCRIPTS’, true );
    define( ‘CONCATENATE_SCRIPTS’, true );
    define( ‘ENFORCE_GZIP’, true );

    /* Updates */
    define( ‘WP_AUTO_UPDATE_CORE’, true );
    define( ‘DISALLOW_FILE_EDIT’, true );

    Again, the site is loading and working fine. So if there was an issue with actually getting the details from the DB based on aomething in the wp-config would it not be then that the site would have issues. Also, it was working the exact some wp-config file before the last update. So I do not think it is my enviro or wp-config.

    Thread Starter David

    (@digitalpurenetworks)

    Sorry I forgot to mention, the “update” was Ninja-Firewall not WP. I am using 3.8.1 and have been since it launched. Only change is Ninja Firewall.

    Plugin Author nintechnet

    (@nintechnet)

    Can you paste the following code into a PHP file, upload it into WordPress root folder, and call it from your browser? It will give more details about the problem.

    <?php
    
    if (! file_exists('wp-config.php') ) {
    	die("Cannot find wp-config.php." );
    }
    if (! $fh = fopen('wp-config.php', 'r') ) {
    	die("cannot open wp-config.php");
    }
    while (! feof($fh)) {
    	$line = fgets($fh);
    	if ( preg_match('/^\s*define\s*\(\s*\'DB_NAME\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_NAME = $match[1];
    	} elseif ( preg_match('/^\s*define\s*\(\s*\'DB_USER\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_USER = $match[1];
    	} elseif ( preg_match('/^\s*define\s*\(\s*\'DB_PASSWORD\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_PASSWORD = $match[1];
    	} elseif ( preg_match('/^\s*define\s*\(\s*\'DB_HOST\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_HOST = $match[1];
    	} elseif ( preg_match('/^\s*\$table_prefix\s*=\s*\'(.+?)\'/', $line, $match) ) {
    		$table_prefix = $match[1];
    	}
    }
    fclose($fh);
    
    if ( empty($DB_NAME) ) {
    	echo "<p>cannot read DB_NAME</p>";
    } else {
    	echo "<p>DB_NAME: OK</p>";
    }
    if ( empty($DB_USER) ) {
    	echo "<p>cannot read DB_USER</p>";
    } else {
    	echo "<p>DB_USER: OK</p>";
    }
    if ( empty($DB_PASSWORD) ) {
    	echo "<p>cannot read DB_PASSWORD</p>";
    } else {
    	echo "<p>DB_PASSWORD: OK</p>";
    }
    if ( empty($DB_HOST) ) {
    	echo "<p>cannot read DB_HOST</p>";
    } else {
    	echo "<p>DB_HOST: OK</p>";
    }
    if ( empty($table_prefix)){
    	echo "<p>cannot read table_prefix</p>";
    } else {
    	echo "<p>table_prefix: OK</p>";
    }
    
    ?>
    Thread Starter David

    (@digitalpurenetworks)

    DB_NAME: OK

    DB_USER: OK

    DB_PASSWORD: OK

    DB_HOST: OK

    cannot read table_prefix

    Thread Starter David

    (@digitalpurenetworks)

    Ok, so I figured it out. For some reason I had ” instead of ‘ around the prefix field.

    $table_prefix = “myunique_”;
    vs
    $table_prefix = ‘myunique_’;

    I changed the prefix, and re-enabled the plugin and it is working. I looked at my backups for the last few months and it has always been with ” instead of ‘ yet the plugin worked (or at least did not give a warning).

    Plugin Author nintechnet

    (@nintechnet)

    That’s it, you found it !

    NinjaFirewall needs to read the conf file line by line. That can be tricky sometimes.
    Unlike WordPress, it cannot use the PHP include() or require() functions to read it because that would load the core part of WordPress too.

    inlinewout

    (@inlinewout)

    Like many others I have my db credentials stored outside of public_html and the wp-config file uses a require once to call them.

    This results in the same error as described above.

    Is there a way to get ninjafirewall to work if this is the case?

    Plugin Author nintechnet

    (@nintechnet)

    You can tell the firewall where is your wp-config file. See this link.

    inlinewout

    (@inlinewout)

    Thanks Nintechnet.
    Sorry to say it doesn’t seem to work for me, The plugin can find the .htninja file, but the db credentials are still not read.

    I’ve tried the file above and it outputs this:
    cannot read DB_NAME
    cannot read DB_USER
    cannot read DB_PASSWORD
    cannot read DB_HOST
    cannot read table_prefix

    The configfile is placed one directory lower than .htninja and outside public_html so I made .htninja look like this:

    $wp_config = ‘onemapdeeper/wp-config.php’;

    WordPress itself has no difficulty finding the db-credentials.
    Do you have suggestions on how to fix this???

    Plugin Author nintechnet

    (@nintechnet)

    $wp_config = ‘onemapdeeper/wp-config.php’;

    You need to enter the full path to the wp-config (e.g., ‘/home/user/whatever/onemapdeeper/wp-config.php’), not the relative path.
    The firewall script is in your plugins directory and won’t be able to access ‘onemapdeeper/wp-config.php’ otherwise.

    inlinewout

    (@inlinewout)

    Thanks! It works like a charm now!

    Hi, need some help: could not pass the install test so I deleted the php.ini and replaced it by .users.ini – well works – my phpinfo file told that I can read DB_name,user… and even table_prefix; so what is my problem now: even though I could go through the config pages I am still receiving the message: “NinjaFirewall fatal error : cannot connect to WordPress database. Please review your installation. Your site is not protected.” What this means if everything looks like works well and how can I verify if any problem is going on and how is it happening??? Please any help will be appreciated – wp ver 3.9 with all plugins up to date… thanks

    Plugin Author nintechnet

    (@nintechnet)

    Hi,

    Can you upload this script to your server and run it from your browser ? It is similar to the above one, but in addition it will attempt to connect to the DB and output an error message in case of a problem:

    <?php
    
    if (! file_exists('wp-config.php') ) {
    	die("Cannot find wp-config.php." );
    }
    if (! $fh = fopen('wp-config.php', 'r') ) {
    	die("cannot open wp-config.php");
    }
    while (! feof($fh)) {
    	$line = fgets($fh);
    	if ( preg_match('/^\s*define\s*\(\s*\'DB_NAME\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_NAME = $match[1];
    	} elseif ( preg_match('/^\s*define\s*\(\s*\'DB_USER\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_USER = $match[1];
    	} elseif ( preg_match('/^\s*define\s*\(\s*\'DB_PASSWORD\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_PASSWORD = $match[1];
    	} elseif ( preg_match('/^\s*define\s*\(\s*\'DB_HOST\'\s*,\s*\'(.+?)\'/', $line, $match) ) {
    		$DB_HOST = $match[1];
    	} elseif ( preg_match('/^\s*\$table_prefix\s*=\s*\'(.+?)\'/', $line, $match) ) {
    		$table_prefix = $match[1];
    	}
    }
    fclose($fh);
    
    if ( empty($DB_NAME) ) {
    	echo "<p>cannot read DB_NAME</p>";
    } else {
    	echo "<p>DB_NAME: OK</p>";
    }
    if ( empty($DB_USER) ) {
    	echo "<p>cannot read DB_USER</p>";
    } else {
    	echo "<p>DB_USER: OK</p>";
    }
    if ( empty($DB_PASSWORD) ) {
    	echo "<p>cannot read DB_PASSWORD</p>";
    } else {
    	echo "<p>DB_PASSWORD: OK</p>";
    }
    if ( empty($DB_HOST) ) {
    	echo "<p>cannot read DB_HOST</p>";
    } else {
    	echo "<p>DB_HOST: OK</p>";
    }
    if ( empty($table_prefix)){
    	echo "<p>cannot read table_prefix</p>";
    } else {
    	echo "<p>table_prefix: OK</p>";
    }
    
    echo "<p>Attempting to connect to the DB: ";
    
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME);
    if ($mysqli->connect_error) {
    	die('ERROR: ' . $mysqli->connect_error) . '</p>';
    }
    echo 'OK</p>';
    
    $mysqli->close();
    
    ?>

    Thanks for your quick support, the result to this code is listed:

    DB_NAME: OK

    DB_USER: OK

    DB_PASSWORD: OK

    DB_HOST: OK

    table_prefix: OK

    Attempting to connect to the DB: ERROR: Unknown MySQL server host ‘dbxxxxxx.db.1and1.com:3306’ (3)

    where dbxxxxxx, the xxxxxx are a value. Can you help?

    let me say that my wp installation was dowe by /kunde/htmdocs….. and your ninja when installing ask me where it was to use the root or the directory direction that started with /htmdocs….. and I made the installation first with /htm.. and now by /kunde – it made a difference at the first letters in the line that pointed to my root in the .httacces but I have regular access after I deleted the php.ini and tried with the .users.ini as I told already – perhaps this can give more insight about my installation.

Viewing 15 replies - 1 through 15 (of 28 total)
  • The topic ‘Fatal Error: DB Credentials’ is closed to new replies.