Since MariaDB 10.6 the default socket has changed from /tmp/mysql.sock to /var/run/mysql/mysql.sock. It would be nice if databases/php8[2-5]-pdo_mysql would also be able to be built with this new path. Discussion started with bug #267835 in November 2022, but just recently in bug #267835 comment 17 I got encouraged to try to look again into this. I have tried a few things, but so far I was unable to build databases/php84-pdo_mysql with the new default path to /var/run/mysql/mysql.sock default. As Marcos Mello thinks it seems that the two ports databases/php84-pdo_mysql and databases/php84-mysqli may need to be built together and not as individual ports. I at least was able to build databases/php84-mysqli with the new default path, but it failed for the binaries and libraries in lang/php84, www/mod_php84 and databases/php84-pdo_mysql. I will not repeat the whole long details / outputs here, as everything is available starting at bug #267835 comment 18. Hopefully someone with more FreeBSD Ports, and especially PHP ports related know-how is able to come up with a solution for this. As a workaround in /usr/local/etc/php.ini the option 'pdo_mysql.default_socket = /var/run/mysql/mysql.sock' needs to be set, or else MariaDB 10.6+ may be reverted in /usr/local/etc/mysql/my.cnf with the "old" default path in the [client-server] section with 'socket = /tmp/mysql.socket'.
This might do the trick: diff --git a/lang/php85/Makefile b/lang/php85/Makefile index 6a6c5a51e6b4..47d402e56e47 100644 --- a/lang/php85/Makefile +++ b/lang/php85/Makefile @@ -144,7 +144,8 @@ CONFIGURE_ENV+= ac_cv_decimal_fp_supported="no" \ lt_cv_path_SED="sed" \ OPENSSL_CFLAGS="-I${OPENSSLINC}" \ OPENSSL_LIBS="-L${OPENSSLLIB} -lssl -lcrypto" \ - PHP_OPENSSL=yes + PHP_OPENSSL=yes \ + PHP_MYSQL_SOCK=/var/run/mysql/mysql.sock post-patch: @${TOUCH} ${WRKSRC}/ext/php_config.h
That didn't work, but this does: diff --git a/lang/php85/Makefile b/lang/php85/Makefile index 6a6c5a51e..f547b2fe3 100644 --- a/lang/php85/Makefile +++ b/lang/php85/Makefile @@ -386,7 +386,7 @@ PHP_HEADER_DIRS= libmbfl libmbfl/filters libmbfl/mbfl libmbfl/nls . endif . if ${PHP_MODNAME} == "mysqli" -CONFIGURE_ARGS+= --with-mysqli +CONFIGURE_ARGS+= --with-mysqli --with-mysql-sock=/var/run/mysql/mysql.sock . endif . if ${PHP_MODNAME} == "odbc" @@ -435,6 +435,8 @@ OPTIONS_DEFAULT= MYSQLND MYSQLND_DESC= Use MySQL Native Driver +CONFIGURE_ENV+= PHP_MYSQL_SOCK=/var/run/mysql/mysql.sock + MYSQLND_CONFIGURE_ON= --with-pdo-mysql=mysqlnd MYSQLND_CONFIGURE_OFF= --with-pdo-mysql=${LOCALBASE} \ --with-zlib-dir=/usr
None of these are correct. I will fix it in the weekend.
I have looked at the overall problem in depth and there are lots of caveats and a buildtime config flag is not at all the solution. All flavors of MySQL and MariaDB actually supports overriding the run dir through their config files or rc scripts so even I override one path there will be people with different requirements. So let's leave MySQL and MariaDB out of the equation and return to discuss on how php works or how the pdo_mysql extension actually works. Currently we support building pdo_mysql either with mysqlnd support or without it meaning using the mysql/mariadb libraries. Now the problem is mysqlnd has a default bindings to '/tmp/mysql.sock' which is not user overridable during build time. You can change the runtime behavior with `pdo_mysql.default_socket` in the relevant php.ini file. And in case if you do not want to use mysqlnd that is if the OPTION MYSQLND is turned off it will automatically use the relevant mysql/mariadb config. Now the question becomes why I cannot just detect automagically based on the mysql flavor being installed. The answer is during build time the server is not running and server configurations are dynamic and as said earlier can have custom run directories making the entire build time configuration useless. So the actual solution is the runtime configuration. And if you want what I can do is add support for mysqli backend as an option for pdo_mysql and then we will need two different configuration lines I believe which are `pdo_mysql.default_socket` and `mysqli.default_socket`. In the earlier days mysql supported compiling either against mysqlnd or an available system libmysql library. But if I am not mistaken compiling against a system library support was dropped from php81 or php82. So the same problem will keep on going. The actual problem lies neither on pdo_mysql nor on mysqli. The actual problem lies on mysqlnd and if you are brave enough for upstream patches here are the relevant codes: https://github.com/php/php-src/blob/95b5b4879938387711fe460fc02773a2429b5539/ext/mysqlnd/mysqlnd_connection.c#L525-L543 So the solution is: 1. If you want mysqlnd driver use `pdo_mysql.default_socket` config in php.ini 2. If you do not want mysqlnd driver build php-pdo_mysql without this option and php will pickup the relevant mysql config and connect properly.
PHP / MySQL / MariaDB are all working as they should, but something that worked by default for 20 years now requires user intervention. What an amazing time we live in. Rant of a frustrated user about the direction IT is heading.