Moodle
  1. Moodle
  2. MDL-25910

can not install using custom mysql or postgresql socket location

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.0.2
    • Component/s: Installation
    • Labels:
    • Environment:
    • Database:
      MySQL
    • Difficulty:
      Moderate
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      15922

      Description

      In a chroot jailed environment, using socket only mysqli connection, I always got:
      [Sat Jan 08 17:55:56 2011] [error] [client 193.225.122.131] PHP Warning: mysqli::mysqli() expects parameter 5 to be long, string given in /web/www/openwide-moodle/
      lib/dml/mysqli_native_moodle_database.php on line 276
      [Sat Jan 08 17:55:56 2011] [error] [client 193.225.122.131] PHP Warning: mysqli::set_charset() [<a href='mysqli.set-charset'>mysqli.set-charset</a>]: Couldn't fetch
      mysqli in /web/www/openwide-moodle/lib/dml/mysqli_native_moodle_database.php on line 286
      [Sat Jan 08 17:55:56 2011] [error] [client 193.225.122.131] PHP Warning: mysqli_native_moodle_database::get_server_info() [<a href='mysqli-native-moodle-database.
      get-server-info'>mysqli-native-moodle-database.get-server-info</a>]: Couldn't fetch mysqli in /web/www/openwide-moodle/lib/dml/mysqli_native_moodle_database.php on
      line 326
      [Sat Jan 08 17:55:56 2011] [error] [client 193.225.122.131] PHP Warning: mysqli_native_moodle_database::get_server_info() [<a href='mysqli-native-moodle-database.get-server-
      info'>mysqli-native-moodle-database.get-server-info</a>]: Couldn't fetch mysqli in /web/www/openwide-moodle/lib/dml/mysqli_native_moodle_database.php on line 326
      [Sat Jan 08 17:55:56 2011] [error] [client 193.225.122.131] PHP Warning: mysqli::query() [<a href='mysqli.query'>mysqli.query</a>]: Couldn't fetch mysqli in /web/www/
      openwide-moodle/lib/dml/mysqli_native_moodle_database.php on line 769
      [Sat Jan 08 17:55:56 2011] [error] [client 193.225.122.131] PHP Fatal error: Call to a member function fetch_assoc() on a non-object in /web/www/openwide-moodle/lib/dml/
      mysqli_native_moodle_database.php on line 774
      [Sat Jan 08 17:56:13 2011] [error] [client 193.225.122.131] Default exception handler: Error reading from database Debug: No database selected\nSHOW TABLES\n[NULL]\n* line 391 $
      line 1366 of /lib/upgradelib.php: call to mysqli_native_moodle_database->get_tables()\n* line 100 of /admin/index.php: call to core_tables_exist()\n

      I could narrow the problem to mysqli_native_moodle_database.php. Int hat I made the following hard-coding with my very basic php knowledge:

      this (line 276):
      $this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport);
      to this:
      $this->mysqli = new mysqli('localhost', $dbuser, $dbpass, $dbname, 3306, "/web/mysql/mysql.sock" );

      (dport varible were unset, socket missing)

      my config.php settings:
      $CFG->dbtype = 'mysqli';
      $CFG->dbhost = 'localhost:/web/mysql/mysql.sock';
      $CFG->dbname = 'moodle_openwide';
      $CFG->dbuser = 'moodle_openwide';
      $CFG->dbpass = password;
      $CFG->prefix = 'mdl_';

      $CFG->dblibrary = 'native'; // 'native' only at the moment

      $CFG->dboptions = array(
      'dbpersist' => true, // should persistent database connections be
      // used? set to 'false' for the most stable
      // setting, 'true' can improve performance
      // sometimes
      'dbsocket' => true, // should connection via UNIX socket be
      // used? if you set it to 'true' here,
      // set dbhost to 'localhost'
      'dbport' => '', // the TCP port number to use when connecting
      // to the server. keep empty string for the
      // default port
      );

      since I was unable to specify elsewhere the socket path, I had to define in the dbhost. That's why it contains more than just localhost...

        Activity

        Hide
        Petr Škoda added a comment -

        Thanks for the report.

        Show
        Petr Škoda added a comment - Thanks for the report.
        Hide
        Éliás Tamás added a comment -

        I can see in the resolution a test case:
        How to test:
        1/ configure mysql/php to accept both socket and port connections; enable debug mode in moodle

        Question. What happens if my system configured to use only socket connection? So I have a skip-networking option in mysql. It does not listening on any port. Will the patch work in this situation?

        Show
        Éliás Tamás added a comment - I can see in the resolution a test case: How to test: 1/ configure mysql/php to accept both socket and port connections; enable debug mode in moodle Question. What happens if my system configured to use only socket connection? So I have a skip-networking option in mysql. It does not listening on any port. Will the patch work in this situation?
        Hide
        Petr Škoda added a comment -

        Socket connections are used when dbhost is set to "localhost" and in that case the port is ignored.

        Show
        Petr Škoda added a comment - Socket connections are used when dbhost is set to "localhost" and in that case the port is ignored.
        Hide
        Éliás Tamás added a comment -

        Okay then, I reverse the situation. In a chrooted environment, especially when using certain BSDs, it is very common, that each jail has a network interface like this: 127.0.0.2, 127.0.0.3. And sockets are not binded to each jails' file structure, instead they specify that mysql is listneing on 127.0.0.1:port. On some cases this kind of configuration is better what I'm using, because network access is esily controllable via iptables and certain speed and othe rlimitaions can be applied. So the host is localhost, but the connection is not socket.

        So it would be a better solution, if the configurator could decide, if he is using socket or port connection. If this is the case now, with this patch, I didn't say anything....

        Show
        Éliás Tamás added a comment - Okay then, I reverse the situation. In a chrooted environment, especially when using certain BSDs, it is very common, that each jail has a network interface like this: 127.0.0.2, 127.0.0.3. And sockets are not binded to each jails' file structure, instead they specify that mysql is listneing on 127.0.0.1:port. On some cases this kind of configuration is better what I'm using, because network access is esily controllable via iptables and certain speed and othe rlimitaions can be applied. So the host is localhost, but the connection is not socket. So it would be a better solution, if the configurator could decide, if he is using socket or port connection. If this is the case now, with this patch, I didn't say anything....
        Hide
        Petr Škoda added a comment -

        mysql driver treats '127.0.0.1' and 'localhost' as different things! The first never uses sockets, the second is using sockets. Do not ask me why, the PHP manual is confusing too...

        Show
        Petr Škoda added a comment - mysql driver treats '127.0.0.1' and 'localhost' as different things! The first never uses sockets, the second is using sockets. Do not ask me why, the PHP manual is confusing too...
        Hide
        Éliás Tamás added a comment -

        erm... May god bless the developers....

        Nice work then, thanx. Please apply a patch for the config-dist.php too, so it would be clear for everyone. I'm sure, it is a great source of misconfigurations....

        Show
        Éliás Tamás added a comment - erm... May god bless the developers.... Nice work then, thanx. Please apply a patch for the config-dist.php too, so it would be clear for everyone. I'm sure, it is a great source of misconfigurations....
        Hide
        Petr Škoda added a comment -

        I am adding support for custom postgresql sockets too. The config-dist.php is updated too. thanks!

        Show
        Petr Škoda added a comment - I am adding support for custom postgresql sockets too. The config-dist.php is updated too. thanks!

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: