View Full Version : Virtual Hosting issues with mysql.sock
matt_idg
2003-08-01, 16:25 PM
Virtually untouched RH 7.3 (Valhalla) default install from ServerBeach.
All virtual hosting accounts using MySQL are created & activated with broken database functionality:
Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in /var/www/html/index.php on line 3
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in /var/www/html/index.php on line 3
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
A temporary fix is to manually link /home/virtual/<sitename>/var/lib/mysql/mysql.sock (which doesn't exist by default) to /var/lib/mysql.sock in the non-virtual filesystem (/dev/hda2). However, after a week or so something occurs which causes the manually created mysql.sock's in the virtual hosting dir's to break, and I have to go back through and manually re-create all of them.
I'm looking for any insight someone may have to this.
Thanks.
Matt Decatur
awsolutions
2003-08-01, 16:27 PM
Hey,
A long time ago I know I had a problem with a symlink not existing in the /tmp directory. Try that maybe.
Create a symlink:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
and see if that helps.
awsolutions
2003-08-01, 16:29 PM
Also,
what is on /var/www/html/index.php on line 3??
matt_idg
2003-08-01, 16:55 PM
line 3 is as follows:
$db_conn = mysql_connect($db_host,$db_user,$db_pass) or die(mysql_error());
per your suggestion, I created a link to mysql.sock in /tmp, which didn't resolve the problem.
all database activity fails in all virtual hosting accounts that I don't manually create the /home/virtual/<sitename>/var/lib/mysql/mysql.sock for. When using the command line mysql client everything works fine, the error is only when accessing DB's via PHP.
Striker
2003-08-01, 17:03 PM
I suggest you check your php.ini (use locate php.ini to find it) to see which socket file it's looking for.
matt_idg
2003-08-01, 17:13 PM
/etc/php.ini and the php.ini files located in /home/virtual/<sitename>/etc have no mysql socket specified, so it defaults to the one specified in /etc/my.cnf, which is /var/lib/mysql/mysql.sock.
However, in the virtual hosting /etc dir (/home/virtual/<sitename>/etc/my.cnf), only the [client] section is defined with no options regarding mysql socket or other mysqld related stuff.
Striker
2003-08-01, 17:20 PM
I suggest you manually specify one in your php.ini because it may be looking under your virtual directories for the my.cnf
matt_idg
2003-08-01, 17:29 PM
I defined mysql.default_socket in both the main system php.ini and the virtual hosting php.ini, and neither resolved the problem.
It seems as though httpd gets ch'rooted to the virtual hosting dir, where /var/lib/mysql/mysql.sock doesn't exist by default, but the link can traverse the chroot and write to the mysql.sock located in the main system just fine when it's created. However the link doesn't stay valid forever, and the same mysql.sock error presents itself and i have to delete and re-create the link to restore functionality.
Striker
2003-08-01, 17:44 PM
If you're running a chroot'ed webserver, I don't see any way to resolve that issue without doing it like you are.
However, I suppose you could make a cron job as root and have it re-symlink everything every once in a while.
matt_idg
2003-08-01, 17:53 PM
How can I tell if the webserver is chroot'ed? Is it by default on Valhalla?
Venzia
2003-08-01, 17:57 PM
I had the same problem.
Make sure permissions on the mysql.sock file are readable by apache.
knightfoo
2003-08-04, 18:22 PM
The best solution for this is probably to use TCP connections instead of socket connections. In many virtualhosting environments, the virtual directories are chroot'ed and it is impossible to have a socket file in every virtual directory. Also, the location of the socket file varies from system to system so you may have to change your code frequently. It is perfectly safe to have mysqld listen on 127.0.0.1:3306 so local processes can connect. Using TCP connections avoids any chroot, location, or permissions problems associated with using the socket file.
-knightfoo
matt_idg
2003-08-04, 20:42 PM
Is there an option(s) I should set in php.ini or httpd.conf to have PHP utilize TCP ports instead of sockets?
knightfoo
2003-08-04, 20:49 PM
http://us4.php.net/manual/en/function.mysql-connect.php
matt_idg
2003-08-04, 20:55 PM
Problem solved!
set 127.0.0.1 as mysql.default_host and commented out mysql.default_socket in /etc/php.ini -- Thank you knight!
Hi,
HTH
On my postnuke/xaraya (php cms's) I also had to make sure the configurations for these programs used "127.0.0.1" instead of "localhost".
I guess it's implied in the documentation, but adding it here for those that didn't quite find it.
Sam T.
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.