Warning: mysqli_connect(): (HY000/2002): No such file or directory

I had the same problem but the issue was something related to php.ini file.

I had to edit these two lines in /etc/php.ini (or wherever your php.ini is located):

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

Restart apache server to make sure the changes are reflected.

sudo apachectl restart

Alright, I just found the solution. The problem turned out to be that the host shouldn't have been localhost, but 127.0.0.1. I always thought localhost and 127.0.0.1 was the same, but it turned out to be different.

So maybe as a tip for future users, always use the ip when in doubt.

Tags:

Mysql

Php

Mysqli