First of all, sorry if my English is not too good.
I am facing a problem that I couldn’t solve browsing the web nor the forums
I set up a simple Virtualmin server, and created a few virtual servers. Http browsing, going to phpMyAdmin goes well, I can browse databases from there no issues.
I used a simple test script to test PHP connection to MySQL on one of the site which is :
When $host value is localhost, I get the error : SQLSTATE[HY000] [2002] No such file or directory
When i put 127.0.0.1, the connection works.
Already tried :
I already looked at php configs to set the pdo and mysqli default sockets to /run/mysqld/mysqld.sock, restarted Apache, PHP-FPM, MariaDB
I checked file permissions and ownership on the socket file which seems correct to me
srwxrwxrwx 1 mysql mysql 0 28 nov. 15:52 /run/mysqld/mysqld.sock
From browsing and searching for a solution, it seems I need to find a way for my site on my virtual server to be able to connect through localhost which is a socket, and not the TCP way with 127.0.0.1. But getting no success.
Could someone help me understand what I’m doing wrong and solve this ?
Update, disabling the Jailkit for the domain makes it work. But I still would like to enable it. Shoud I edit the ini file to add the path to the mysqld.sock to make it work ?
From what I keep on seeing, it seems it’s a problem that php in a jailed virtual server cannot access the MySQL socket which is in /var/run/mysqld/mysqld.sock.
It seems the solution is to use the IP address instead of Hostname which causes the connection to make a “TCP” connection rather than a “socket” connection.
If their jail doesn’t have /etc/hosts in it, it obviously can’t work.
A jail must have every file that is needed, because a jailed program can’t go outside the jail to find the system /etc/hosts file, or whatever else it needs.
I ended up removing the jailkit from the virtual servers. What I was afraid doing that was that connecting through FTP would allow browsing directories or viewing homes they shouldn’t. But ProFTPd does the job of limiting users to their homes.
Since they only use FTP to upload files and phpMyAdmin to manage DB, no SSH or anything, the jailkit on the Virtual Server is overkill and not needed.
Yes, chroot jails do not apply to ProFTPd logins, but ProFTPd has its own chroot features unrelated to jailkit (and safer).
chroot jails are for the specific case where you must provide ssh access, for some reason, but you also must restrict the user severely in what they can do.