tc2010 Posted November 1, 2012 Share Posted November 1, 2012 I am a bit befuddled here. From CLI, I tested connectivity to a "localhost" MySQL install via php script. It connects with no errors (script is below). I access the same script from a browser, and this error is returned: Connection failure: 2002 Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13) I am unclear why it would work from command-line, but not when called from a browser. Anyone have any advice on this? I don't think it's a firewall issue, but I opened port 3306 nonetheless, and the result is the same. I also made sure the "apache" account has access to "/var/lib/mysql/", and can see "mysql.sock". This is the code in my php test script: <?php $conn = new mysqli('localhost', 'account', 'password', 'test'); if(mysqli_connect_errno()) { echo "Connection failure: " . mysqli_connect_errno() . "<br />Error: ".mysqli_connect_error(); exit(); }else{ echo "Success"; } ?> Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/270176-strange-problem-connecting-to-mysql/ Share on other sites More sharing options...
kicken Posted November 1, 2012 Share Posted November 1, 2012 Connection failure: 2002 Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13) The (13) is the system error code for why exactly it cannot connect. If you lookup that error using the perror utility you get: kicken@linode:~$ /usr/local/mysql/bin/perror 13 OS error code 13: Permission denied As such, you need to check your permissions again. The user your server is running as does not have the proper access rights to open that file. Quote Link to comment https://forums.phpfreaks.com/topic/270176-strange-problem-connecting-to-mysql/#findComment-1389440 Share on other sites More sharing options...
tc2010 Posted November 1, 2012 Author Share Posted November 1, 2012 Thanks for the reply, kicken. The web server is an apache one, and runs under the "apache" uid. I assumed the role of "apache", and ran the script from command-line, and had a successful connection to MySQL. I double-checked to be sure that "apache" has access to "mysql.sock" (I navigated to /var/lib/mysql as "apache" user). mysql.sock is world read/write. I'll try moving mysql.sock to tmp, and see if that helps. Thank you for the assistance. Quote Link to comment https://forums.phpfreaks.com/topic/270176-strange-problem-connecting-to-mysql/#findComment-1389448 Share on other sites More sharing options...
tc2010 Posted November 1, 2012 Author Share Posted November 1, 2012 The problem was selinux. I disabled it entirely, and now apache can access mysql. Quote Link to comment https://forums.phpfreaks.com/topic/270176-strange-problem-connecting-to-mysql/#findComment-1389452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.