Hi there,

is there any way how to install D7 using db socket rather than hostname? My provider provided me with socket (:/tmp/mysql50.sock) and recommended to use it like this:

$dsn = "mysql:unix_socket=/tmp/mysql50.sock;dbname=$database_name";
try {
  $dbh = new PDO($dsn, $user, $password);
}
catch (PDOException $e) {
  echo 'Connection failed: ' . $e->getMessage();
}

However, as I have noticed in includes/database/mysql/database.inc Drupal can not deal with this because it only takes host, port, uname, psswd and dbname into account.

Am I wrong or missing anything? Could you help me, I would like to install D7 as a base for new module development. Is there any way how to install D7 using socket via standard installation way rather than "hacking" settings.php?
Cheers,
Pete.

Comments

dianamontalion’s picture

I have the same issue and had to enable a remote connection to install Drupal 7. Here's what my host says:

The changelog of Drupal 7 states that the database connection is now handled by the PDO abstraction layer of PHP:

Fully rewritten database layer utilizing PHP 5's PDO abstraction layer.

The database connection options are defined on line 28 of includes/database/mysql/database.inc:

$dsn = 'mysql:host=' . $connection_options['host'] . ';port=' . $connection_options['port'] . ';dbname=' . $connection_options['database'];

A socket can be explicitly specified with the "unix_socket" element of the DSN string (http://www.php.net/manual/en/ref.pdo-mysql.connection.php). Unfortunately, the developers of Drupal have not included in the options list the possibility to set a socket for the connection explicitly.

The way you have installed the application is the only solution for our setup. Thank you for pointing our that issue, we will have it in mind when adding a tutorial about installing Drupal 7.

David_Rothstein’s picture

Component: install system » database system

This seems related to (and possibly a duplicate of) #26836: Socket Connection/path support (especially on PostgreSQL)?

Crell’s picture

Status: Active » Closed (duplicate)

Actually it's a duplicate of #561400: No way to specify MySQL socket with DBTNG, which was bumped to D8 due to lack of attention, time, and bot success. If there are hosts that only allow socket connections then we can consider bringing it back down to D7 if someone is willing to work on it.

(And if there are hosts that only allow socket connections, they need to be shot for stupidity. I mean really people...)

dikkjo’s picture

Hello,

this problem is related to a standard implementation in PDO or libmysqlclient ( not sure which one ).

Anyway, if you configure "localhost" as host, sockets will be used by default.
On the other hand, if you set "127.0.0.1" or a DNS name as host, it will create a TCP connection.

I also believe that there are not so many mysql server that do not listen on their TCP port on localhost.
And also I've read on Zend forums that PDO will use the php.ini settings in a future version.

Hope it helps,
Cheers