Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (13)
When I try accessing MySQL from my webpage, I get a blank screen. I can access mysql from my terminal no problem.
I checked my /var/log/httpd/error_log and the following errors appear when I try accessing the webpage Code:
PHP Warning: mysql_pconnect(): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (13) /var/www/html/shenlab/Connection/connShen.php has the following code Code:
<?php $hostname_connShen = "127.0.0.1"; $hostname_connShen = "localhost:/data1/mysql/mysql.sock"; The /etc/my.cnf contains the following Code:
[mysqld] I also tried setting the following booleans but no luck # setsebool httpd_can_network_connect_db 1 # setsebool httpd_can_network_connect 1 The only thing that seems to work is turning off selinux with "setenforce 0". Once I turn off selinux, the web page works perfectly. When I turn it back on, the web page goes blank. Turning off selinux is not an option for me. If anyone has something else for me to try, it would be greatly appreciated. Thanks in advance. |
The socket configuration in my.cnf differs from the socket on which you are trying to connect mysql. You may want to check with --socket or -S command line option to verify mysql connection. In addition, if you do not want to turn off SELinux, you will need to configure it to allow connections to MySQL port and particular socket.
|
Thank you for your timely reply.
I did notice that the error message states "Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’" and the my.cnf has the line "socket=/data1/mysql/mysql.sock" I changed the $hostname in the connShen.php file to $hostname_connShen = "localhost:/data1/mysql/mysql.sock"; That fixed the error message. Now the error message states "Can’t connect to local MySQL server through socket ‘/data1/mysql/mysql.sock’" However, I still get an error message and I still cannot access the webpage unless selinux is turned off. What do you mean by "--socket or -S command line option"? I typed --socket at the linux prompt and I get the message "--socket : command not found ..." |
I figured out what you meant by "--socket".
I logged in as root and turned on selinux using the "setenforce 1" command. I logged in as a user and I typed in the following at the linux command prompt $ mysql -u kwatanabe -p --socket=/data1/mysql/mysql.sock I entered my password and I got in no problem. I connected to the database and I performed a query on one of the tables. I still cant access the webpage though. When I turn off selinux using the "setenforce 0" command, the webpage starts working. Wierd. |
I figured out the problem!
I can't believe such a small problem can cause such a nightmare. I entered the following command as root # restorecon -v /data1 and then everything started working! I hate LINUX. |
Quote:
|
All times are GMT -5. The time now is 07:44 AM. |