1

I have a magento site that works just fine in production. However, when I create an identical clone of the site in a 'dev' subdomain on the same hosting site (for maintenance work) I get the dreaded: "SQLSTATE[HY000] [2002] No such file or directory" error.

My investigation has revealed that indicates that Zend PDO is attempting to connect to a local database using a Unix socket but none exists. This makes sense since MySQL isn't running on localhost, but on a separate server.

What doesn't make sense is why Magento / Zend are attempting to connect to MySQL via unix socket when there is a remote hostname specified in my local.xml !

And, since it will be asked...

  • yes, the credentials and host are correct and connectivity is fine
    • several other webapps in the same subdomain work just fine
    • this is a connection error, not an authentication error
  • yes, I cleared the cache
  • I see many questions with the exact same error message. I think I've provided additional information that was not in any of those other posts. Resolved the fact that for some reason the database connection is attempting to use a local 'socket' rather than an TCP Socket. – MarkE Dec 16 '14 at 16:14
  • What's your config (please redact user/pw/host as necessary)? – benmarks Dec 16 '14 at 17:29
  • I have found a solution, and would like to add it as an Answer. Could you open up this Question so I can share what I discovered? – MarkE Dec 16 '14 at 18:54
2

Through instrumenting my site with debug logging, I discovered Magento was somehow picking up the wrong database configuration information (trying to use localhost).

I had the correct information in local.xml. But Magento was somehow loading connection information from a different .xml file.

I have backups of local.xml for my various debug/test environments(localhost.local.xml, development.local.xml, and live.local.xml) in app/etc. This is so I can easily copy the correct config to local.xml for the specific environment.

Apparently magento is loading these other .xml files and it is overriding the values in local.xml. Isn't magento only supposed to load global.xml and local.xml ?

My solution was to remove all of the extra backup .xml files from the app/etc directory. After doing that my dev site worked fine!

UPDATE: More information on why this is occuring can be found in this answer.

  • Does anyone know how/why Magento was picking up configuration from files other than global.xml nd local.xml? I haven't looked at the code, but is it doing something like loading all .xml files from that app/etc directory? – MarkE Dec 18 '14 at 0:28
  • 1
    I figured it out. Other .xml files in the app/etc directory are overriding my local.xml. Read more in this magento stackexchange entry here – MarkE Dec 21 '14 at 20:16
  • 1
    Magento will load all .xml files in the app/etc/ directory. Always rename anything you do not want loaded (backups, samples) to not have the .xml file extension (.sav, .sam). And they seem to load in alphabetic order, so last man standing wins. – Fiasco Labs Aug 5 '15 at 14:57
  • 1
    Fiasco labs is correct - you need to rename those files so they DON'T end in .xml. We use local.xml.staging, local.xml.production, etc... so that we can keep multiple environment configs tracked in git and then symlink to the correct one in deployment scripts. This does mean you may have to update your IDE's to treat these files as XML files but that usually isn't too hard... – Bryan 'BJ' Hoffpauir Jr. Aug 19 '15 at 7:21
0

It seems a file permissions issue. When you clone a magento folder you have to check and fix file permissions on the new copied directory. Instead magento tries to load the old local.xml from the copy. I usually do this task with a script. I would commented your question, but I don't have enough reputation. There is one answer here that help debugging such kind of issue.

  • What I discovered, and Fiasco Labs confirmed, is that Magento loads ALL .xml files from the app/etc directory so to avoid conflicting configs you need to rename the file extension. Doesn't seem to have anything to do with permissions. – MarkE Aug 20 '15 at 13:37
  • What I have figured out is a real thing, if you are on the same host. I had this experience. Copied local.xml is owned by the original user so if you cp it in an other user folder on the same host it gives you conflicts. Thank's for -1 As I told you I was only commenting not really answering, but at that time I wasn't able to do it. – lizardhr Aug 20 '15 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.