2

I have a Drupal 6 site that I ran for years before walking away about three years ago. I would like to resurrect the site in a more modern CMS and am first considering Drupal 8.

I run my site on a shared server where I have my own mysql socket. In Drupal 6, I connected to the database successfully in settings.php through the following syntax:

ini_set('mysqli.default_socket', '/path/to/my/mysql/socket');
ini_set('mysql.default_socket', '/path/to/my/mysql/socket');
$db_url = 'mysqli://dbuser:dbpass@localhost/dbname';

Looking at Drupal 8's settings.php it's a completely different syntax, and I am stumped on how to configure it correctly either there or on the Database configuration screen during install.php. Googling things like "drupal 8 mysql socket" brings up old articles that aren't relevant anymore.

PHP 7.0 is provided and I don't have write access to the ini, so I can't override the socket there.

I have confirmed that the database is running with this command:

mysqladmin --socket=/path/to/my/mysql/socket --user=dbuser -p status

Any help would be greatly appreciated on how to get the database setup in Drupal 8, thank you.

Edit: from Clive's suggestion I added the ini_set() lines above to Drupal 8's settings.php to no avail. I'm assuming it's user error at this point so I'm still trying things.

2
  • What happens if you just specify "localhost" as the hostname? On our setup this causes the Unix socket to be used. For true localhost TCP connection we need to specific 127.0.0.1.
    – imclean
    Commented Feb 28, 2019 at 21:34
  • I tried every variation of the advanced options. This was with the ini_sets in place so I'm not sure what was going on. But then I made a very simple test.php that did the ini_set and then a new PDO() passing it my socket string and that worked fine.
    – Greg Noe
    Commented Feb 28, 2019 at 21:40

1 Answer 1

1

According to this Drupal issue, setting the socket in the UI is just not possible right now: (at least in 8.6.10)

https://www.drupal.org/project/drupal/issues/793200

I also could not figure out how to set the socket in sites/default/settings.php.

I had to resort to hardcoding my socket in this file:

core/lib/Drupal/Core/Database/Driver/mysql/Connection.php

This block of code:

    // The DSN should use either a socket or a host/port.
    if (isset($connection_options['unix_socket'])) {
      $dsn = 'mysql:unix_socket=' . $connection_options['unix_socket'];
    }
    else {
      // Default to TCP connection on port 3306.
      $dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . (empty($connection_options['port']) ? 3306 : $connection_options['port']);
    }

I could not find any way to set "unix_socket" value on $connection_options, so I resorted to hardcoding it before this block like:

$connection_options['unix_socket'] = '/path/to/my/mysql/socket';

Your Answer

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

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