friendica / docker

Docker image for Friendica
https://friendi.ca
GNU Affero General Public License v3.0
45 stars 18 forks source link

Can't connect to unix mysql socket #138

Closed LinAGKar closed 3 years ago

LinAGKar commented 3 years ago

I'm running the friendica:stable-fpm container. I've mounted the socket from mariadb into the container on a volume, and set:

      - MYSQL_HOST=localhost
      - MYSQL_PORT=/var/run/mysqld/mysqld.sock
      - MYSQL_DATABASE=friendica
      - MYSQL_USER=friendica
      - MYSQL_PASSWORD_FILE=/run/secrets/friendica_db_password

if I then go into the container in a shell and install mariadb-client, I can successfully connect to the DBMS with mariadb -p"`cat "$MYSQL_PASSWORD_FILE"`" -u "$MYSQL_USER" "$MYSQL_DATABASE", but the actual friendica server is not able to connect.

nupplaphil commented 3 years ago

Try the following settings for Host/Port:

      - MYSQL_HOST=/var/run/mysqld/mysqld.sock
      - MYSQL_PORT=

or even fewer

      - MYSQL_HOST=/var/run/mysqld/mysqld.sock

I think the combination localhost and as port a socket doesn't work, it becomes: localhost:/var/run/mysqld/mysqld.sock

See here: https://github.com/friendica/friendica/blob/44ee4a54b49cf7c6f4cbb2bc760b09be86cb8cfb/src/Database/Database.php#L95-L98

LinAGKar commented 3 years ago

I've tried that to, as well as MYSQL_HOST=/var/run/mysqld/ and MYSQL_HOST=localhost:/var/run/mysqld/mysqld.sock, and I've tries entering /var/run/mysqld/mysqld.sock, localhost:/var/run/mysqld/mysqld.sock and unix:/var/run/mysqld/mysqld.sock as the database server name in the install wizard.

LinAGKar commented 3 years ago

From what I understand from the source and the documentation, it would need to set unix_socket in order to specify a custom unix socket path. Otherwise, if you set host to localhost, it will use the default, which depends on what it's compiled against.

LinAGKar commented 3 years ago

If I change pdo_mysql.default_socket to /var/run/mysqld/mysqld.sock in /usr/local/etc/php/php.ini-production, and set the host to localhost, that seems to work. This seems to be the only way.

nupplaphil commented 3 years ago

@annando do you know what Friendica does support for host/port settings? I think there's just a general host config entry, so at least setting just the host should have worked.

annando commented 3 years ago

When MYSQL_PORT is given, then it is added to the hostname: https://github.com/friendica/friendica/blob/develop/src/Database/Database.php#L96-L98

nupplaphil commented 3 years ago

Yes, but even in case it isn't set, it doesn't work. My question is if you know that socket connections per se should work.

annando commented 3 years ago

This is something I don't know.

LinAGKar commented 3 years ago

Nevermind about php.ini-production, that does not help. What actually did was symlinking /tmp/mysql.sock to the socket, which I'd done during the troubleshooting earlier. That gets it past the database page in the install wizard, but the automated setup still doesn't work. I still just get:

Waiting for MySQL localhost initialization...
............................................................................................................................................................................................................................................................................................................
[ERROR] Waited 300 seconds, no response
nupplaphil commented 3 years ago

At least I know the answer now. We currently don't support socket connections at all :) - see https://github.com/friendica/friendica/issues/6606

  1. PDO - We would need the parameter unix_socket in our DSN to enable this feature (see https://www.php.net/manual/en/ref.pdo-mysql.connection.php ). https://github.com/friendica/friendica/blob/99a145f7cff984f19e8adbc018a8b631aaa58e0f/src/Database/Database.php#L128-L136

  2. mysqli - We would need the parameter $socket at our mysqli() call (see https://www.php.net/manual/en/mysqli.construct.php ). https://github.com/friendica/friendica/blob/99a145f7cff984f19e8adbc018a8b631aaa58e0f/src/Database/Database.php#L151-L153

Both are not implemented, so I'm closing this issue now. @LinAGKar feel free to reopen it in case you need further support