3

I am trying to setup moodle and running into a connection problem. See the config below:

<?php  // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'gs_vle';
$CFG->dbuser    = 'root';
$CFG->dbpass    = 'root';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
 'dbpersist' => 0,
 'dbport' => '',
 'dbsocket' => '',
);

$CFG->wwwroot   = 'http://localhost/~ryanme/work/vle/';
$CFG->dataroot  = '/Users/ryanme/sites/work/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;

require_once(dirname(__FILE__) . '/lib/setup.php');

I am getting a database connection error. See the error below:

Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /Users/ryanme/Sites/work/vle/lib/dml/mysqli_native_moodle_database.php on line 79

Things I have done

  • Logged in with the root user via terminal and checked I can see the database with show databases;. This works fine.
  • Checked the settings are correct over and over.
  • Compared the config file to teams setup and it's pretty much the same.
  • Ensured the mysqli module is enabled for PHP. It is.

What can I do to figure out what is causing this database connection error?

8
  • is databeas type really mysqli? is this www root correct? Commented Jun 15, 2015 at 15:39
  • How do I check that? I would have expected that to be the default for mysql. Commented Jun 15, 2015 at 15:42
  • can you load your wwwroot in browser? it has to be the destination of index.php Commented Jun 15, 2015 at 15:44
  • Yes. I can navigate to moodle as well and follow the wizard to setup the config file via the front end, but that does not work either. Commented Jun 15, 2015 at 15:45
  • ca you access this path? /Users/ryanme/Sites/work/vle/lib/dml/mysqli_native_moodle_database.php if not you have a misconfiguration of your www root / vhost Commented Jun 15, 2015 at 15:46

3 Answers 3

1

After more investigation. I found that this was due to "mysql on OS X gets the locations of the required sock file a bit wrong". Once I created the sym links required for the mysql sock file everything worked.

See linked issue for details.

Sign up to request clarification or add additional context in comments.

Comments

0

I had had the same problem. To solve this issue I put the name of the server instead localhost

$CFG->dbhost = '<name-of-the-server>';

Comments

0

I got this error after an app installation changed the database password of Moodle. To fix this, I updated the password in Moodle's config.php and, sure enough, my problem was resolved.

Perhaps Moodle should have some original database errors, like "database connection failed"? That could save a lot of time, instead of that generic error. Just a suggestion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.