LycheeOrg / Lychee-v3

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.

Home Page:https://lycheeorg.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for unix socket connections

0xpr03 opened this issue · comments

commented

Detailed description of the problem

It is currently impossible to connect via sockets to the DB.
This would allow easier connection, for example when exposing the Host-DB server to a docker container running lychee. That way no bind has to be changed to or the network of container & host to be shared.

Could you explain your problem in more detail?

I have $dbHost = '127.0.0.1'; in data/config.php and, as far as I can tell, PHP connects to the DB using a socket:

$ netstat -an | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:3306          127.0.0.1:59574         TIME_WAIT  
tcp        0      0 127.0.0.1:3306          127.0.0.1:59572         TIME_WAIT
commented

If you want to run lychee from a docker container you currently cannot connect to mariadb via a unix socket 1 2 3.
This is mandatory if you want to run the mariadb server on the host and connect to it from lychee in docker. This requires both to be in the same network using TCP.
But it is pretty easy to forward a unix socket into the container as it's "just a file". All other options are quite bad:

  • Via --net=host, which imposes a security risk and is not recommended.
  • Binding the mariadb server on the host to 0.0.0.0 (global) and restricting it to localhost & the docker subnet via IP tables.

All in all being able to connect to mysql/mariadb via a unix socket would make this much easier.

Oh, sorry, nomenclature problem. You mean the UNIX domain sockets rather than TCP sockets.

So, just to make sure that I understand the problem now, you are saying that the Lychee server does not support connecting to the database using the UNIX domain sockets?

commented

Yes or at least no docs mentioned any syntax nor was my input working.
Now that you mention it I've got the strong feeling that I may have been missing an identifier ?

You need to enter localhost as the database host name (in this particular case, it's a magic identifier that is not the same as 127.0.0.1). Lychee will use the default socket pathname defined in the mysqli extension, which is I believe /tmp/mysql.sock, but it may be set to something different in your container. Either way, if you need it to be something different, you should be able to override it by providing the line mysqli.default_socket = <pathname> in /etc/php/apache2-php7.3/php.ini (or in an equivalent config file if you are using something else than Apache with mod_php).

commented

So I just set localhost as host and mysqli.default_socket ? I don't have to remove the port entry or anything like that ?

Sorry, where did you enter the port? Are you using Lychee v3 or Lychee-Laravel (to-be-v4)? If you are unsure, what's the name of the config file with DB details?

commented

Using V3 I think. https://hub.docker.com/r/linuxserver/lychee/

config.php

$dbHost = 'localhost'; // Host of the database
$dbUser = 'root'; // Username of the database
$dbPassword = 'root'; // Password of the database
$dbName = 'lychee'; // Database name
$dbTablePrefix = ''; // Table prefix

If I understand you correctly.

commented

Lychee 3.2.16 according to about.

commented

So I got it wrong in my head, there's no port to enter ;)

Yes, you are using v3. You confused me with the port question (since we do have an entry for it in v4).

Your config looks fine as-is. Lychee should be trying to connect using Unix domain sockets (you may need to restart the webserver/fpm/FastCGI/whatever after changing the config). If it doesn't work, then it's probably because the socket pathname that PHP's mysqli extension uses is not the same that MariaDB actually listens on. See my comment above about mysqli.default_socket.

commented

Ok thank you. Otherwise I'll open the issue again ;)