php artisan migrate error when using 'localhost' as DB_HOST #4478

Closed
opened 2026-02-05 08:57:53 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @crgbt on GitHub (Feb 21, 2024).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

I have a scenario whereby when using localhost as the DB_HOST in .env, the database connection fails. When using 127.0.0.1 as the DB_HOST in .env, the database connection is successful.

This issue appears when running php artisan migrate during installation, with the following error:

php artisan migrate --no-interaction --force

In Connection.php line 760:

  SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and
   table_type = 'BASE TABLE')


In Connector.php line 70:

  SQLSTATE[HY000] [2002] No such file or directory

I have the MySQL socket in a non-default location (/data/mysql/mysql.sock) which I suspect may be causing the issue, as you need to specify the client socket to use in my.cnf when using a non-standard socket, and typically when using localhost for MySQL connections this will use the socket, whereas using 127.0.0.1 will use TCP/IP.

  • Could the non-standard socket be causing this issue? If not, does anyone else have any further troubleshooting suggestions,please?
  • Is there a way, like with my.cnf, to specify a non-standard socket in PHP?

Thanks for taking the time to look at my query, and for any advice given.

Exact BookStack Version

v23.12.2

Log Content

No response

Hosting Environment

Distro: Oracle Linux 9.3
PHP: 8.3.3
MySQL: 8.0.32

Originally created by @crgbt on GitHub (Feb 21, 2024). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### Describe the Scenario I have a scenario whereby when using `localhost` as the `DB_HOST` in `.env`, the database connection fails. When using `127.0.0.1` as the `DB_HOST` in `.env`, the database connection is successful. This issue appears when running `php artisan migrate` during installation, with the following error: ``` php artisan migrate --no-interaction --force In Connection.php line 760: SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE') In Connector.php line 70: SQLSTATE[HY000] [2002] No such file or directory ```` I have the MySQL socket in a non-default location (`/data/mysql/mysql.sock`) which I suspect may be causing the issue, as you need to specify the client socket to use in `my.cnf` when using a non-standard socket, and typically when using `localhost` for MySQL connections this will use the socket, whereas using `127.0.0.1` will use TCP/IP. * Could the non-standard socket be causing this issue? If not, does anyone else have any further troubleshooting suggestions,please? * Is there a way, like with `my.cnf`, to specify a non-standard socket in PHP? Thanks for taking the time to look at my query, and for any advice given. ### Exact BookStack Version v23.12.2 ### Log Content _No response_ ### Hosting Environment Distro: Oracle Linux 9.3 PHP: 8.3.3 MySQL: 8.0.32
OVERLORD added the 🐕 Support label 2026-02-05 08:57:53 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Feb 21, 2024):

Hi @crgbt,

Could the non-standard socket be causing this issue?

Yeah, possibly.

Is there a way, like with my.cnf, to specify a non-standard socket in PHP?

Yeah, I think the default location is often built-in during PHP build time, depending on environment/system/build.
There is a pdo_mysql.default_socket option that you may be able to define in php.ini.
Otherwise, it looks like we do accept a DB_SOCKET env option, pointing to the socket, although this is not something we really test nor document, so not really on official support status.

@ssddanbrown commented on GitHub (Feb 21, 2024): Hi @crgbt, > Could the non-standard socket be causing this issue? Yeah, possibly. > Is there a way, like with my.cnf, to specify a non-standard socket in PHP? Yeah, I think the default location is often built-in during PHP build time, depending on environment/system/build. There is a [pdo_mysql.default_socket](https://www.php.net/manual/en/ref.pdo-mysql.php#ini.pdo-mysql.default-socket) option that you may be able to define in php.ini. Otherwise, it looks like we do accept a `DB_SOCKET` env option, pointing to the socket, although this is not something we really test nor document, so not really on official support status.
Author
Owner

@crgbt commented on GitHub (Feb 22, 2024):

Hi @crgbt,

Could the non-standard socket be causing this issue?

Yeah, possibly.

Is there a way, like with my.cnf, to specify a non-standard socket in PHP?

Yeah, I think the default location is often built-in during PHP build time, depending on environment/system/build. There is a pdo_mysql.default_socket option that you may be able to define in php.ini. Otherwise, it looks like we do accept a DB_SOCKET env option, pointing to the socket, although this is not something we really test nor document, so not really on official support status.

Hey @ssddanbrown,

Many thanks for the suggestions. I checked out the pdo_mysql.default_socket option, and changing this to pdo_mysql.default_socket=/data/mysql/mysql.sock (from pdo_mysql.default_socket=, which is the default in Oracle Linux 9 using the Remi PHP 8.3 packages) allows the use of DB_HOST=localhost.

@crgbt commented on GitHub (Feb 22, 2024): > Hi @crgbt, > > > Could the non-standard socket be causing this issue? > > Yeah, possibly. > > > Is there a way, like with my.cnf, to specify a non-standard socket in PHP? > > Yeah, I think the default location is often built-in during PHP build time, depending on environment/system/build. There is a [pdo_mysql.default_socket](https://www.php.net/manual/en/ref.pdo-mysql.php#ini.pdo-mysql.default-socket) option that you may be able to define in php.ini. Otherwise, it looks like we do accept a `DB_SOCKET` env option, pointing to the socket, although this is not something we really test nor document, so not really on official support status. Hey @ssddanbrown, Many thanks for the suggestions. I checked out the `pdo_mysql.default_socket` option, and changing this to `pdo_mysql.default_socket=/data/mysql/mysql.sock` (from `pdo_mysql.default_socket=`, which is the default in Oracle Linux 9 using the Remi PHP 8.3 packages) allows the use of `DB_HOST=localhost`.
Author
Owner

@ssddanbrown commented on GitHub (Feb 23, 2024):

Good to hear that worked for you! I'll therefore close this off.

@ssddanbrown commented on GitHub (Feb 23, 2024): Good to hear that worked for you! I'll therefore close this off.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#4478