Forum

Thread tagged as: Error, Configuration, Blog

Getting Perch could not connect to the database Error & Blog Content Not Visible

After taking about 6 days off from working on my Perch blog, I went to pick back up yesterday and, as you can see at https://resumerelief.com/blog/, the page is there, but none of the 8+ blogs I added and was viewing there last week are visible.

Then I went to log into my blog info at https://resumerelief.com/perch/core/error/db.php and I get the error:

Error Perch could not connect to the database

Please check that the access details specified in config.php are correct. Try again

It's telling me to check the config.php file - a file that when I went through the setup had been automatically filled in - meaning I did not have to copy the code generated at initial setup and now the config.php file is zero bytes (empty), my blog isn't working, I can't log into my Perch blog account and could really use your help with resolving this mystery evaporation of my content ASAP.

What am I missing?

Thanks!!!

Melanie Lenci

Melanie Lenci 0 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Someone or something has deleted the contents of that file. Did you sync up files from a local copy and overwrite it? The information in the config file is what Perch uses to connect to the database so you will need to put back the original content.

I imagine all your content is there in the database (you can always look to check) once you can connect to it again.

Rachel,

I've done nothing at all since last week to any of my Perch/blog files - and everything was there when I left it.

I obviously know that Perch needs info in the config file and Perch automatically placed it there, but now it's mysteriously gone! - can you tell me what info or where I can find the info that needs to be copied into that file?

And I also assume that my content is still in the database - but if I can't login to the database, what good is it to me?

Do I need to raise a private ticket to get some actual help with this issue?

Thanks.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

I'm giving you some actual help here. Perch won't overwrite your config file once it is written so if I were you I'd be finding out what did as you don't want it happening again.

9 times out of 10 if this happens it is because some tool you are using for development - Dreamweaver a common culprit - overwrites your live config with the blank one you have locally, which is why I suggested that as a possible cause. If that is definitely not what has happened then I'd be somewhat concerned about my hosting. There is no code in Perch that could do this.

Presumably you can log into the database on your hosting via your control panel if you know your login details? I suggested that so that you could confirm your content was still there so your mind was at rest that once you had replaced your config file your content would be there and you wouldn't need to replace it.

Just restore your config file from your backup would be the simplest thing. It's just a file that needs replacing. If you don't have a backup for some reason then the following is the content of the config file, you will need to replace the placeholders (beginning with a $) with your actual connection and user details.

<?php
    define('PERCH_LICENSE_KEY', '$licenseKey');

    define("PERCH_DB_USERNAME", '$db_username');
    define("PERCH_DB_PASSWORD", '$db_password');
    define("PERCH_DB_SERVER", "$db_server");
    define("PERCH_DB_DATABASE", "$db_database");
    define("PERCH_DB_PREFIX", "perch2_");

    define('PERCH_TZ', '$tz');

    define('PERCH_EMAIL_FROM', '$userEmail');
    define('PERCH_EMAIL_FROM_NAME', '$userGivenName $userFamilyName');

    define('PERCH_LOGINPATH', '$loginpath');
    define('PERCH_PATH', str_replace(DIRECTORY_SEPARATOR.'config', '', __DIR__));
    define('PERCH_CORE', PERCH_PATH.DIRECTORY_SEPARATOR.'core');

    define('PERCH_RESFILEPATH', PERCH_PATH . DIRECTORY_SEPARATOR . 'resources');
    define('PERCH_RESPATH', PERCH_LOGINPATH . '/resources');

    define('PERCH_HTML5', true);

?>

I am truly baffled as to what has happened because all the copies of my config.php were empty. I don't use a development tool, so that wasn't the culprit.

Since I truly don't even know where to start to "replace the placeholders (beginning with a $) with your actual connection and user details" as you mentioned within the above (as this had been something that Perch had done automatically when I entered my database and user info initially [and while a few of those placeholders I do know off hand, there are 10 and I'm sure I'm bound to mess one of those up and continue to waste time trying to find the right values).

I tried downloading the perch_v2.5.4 files again to see if it would automatically populate that config file as it did the first time, but it did not.

Is there any way that I can backtrack and have that config.php file automatically generated again with all of my connection and user details filled in?

I'm at a loss here because if Perch had not filled that file in for me in the beginning I likely would have realized that I was in over my head and decided that this was all too complicated for me, but since I've already spent hours and hours adding and editing my blog content within your system I'd really like to continue where I left off - customizing my templates.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You would need to reinstall from scratch to get Perch to replace that file, but filling in the placeholders is exactly the same as that process (just not in a form). You need to know:

  • license key
  • database username
  • database password
  • database location (probably localhost)
  • your email
  • your firstname and lastname
  • your perch loginpath (probably /perch if you haven't changed it)

All you need do is paste the above into your blank config file and replace each of those values with exactly what you put in the form when installing Perch.

What value goes within the following $tz:

define('PERCH_TZ', '$tz');

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The default is 'UTC'

While I'm still unsure what happened to essentially erase my config.php data, I was able to recreate the page (and have made backups now) thanks to Rachel's help (thank you!) and after submitting a trouble ticket to my hosting provider (Total Choice Hosting), they resolved what ever issue was occurring.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Great! Glad you have it sorted :)