Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

This issue has me a bit caught off guard. I've just set up this LAMP server and everything appears to be working well until I try running some of my PHP that communicates with the MySQL server.

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

So obviously the MySQL server won't talk to PHP for some reason. I go ahead and connect to it with MySQL client, and have no issues whatsoever logging in and doing queries. I take a look at the systemctl for MySQL and find that it's purposely denying the connection for some reason.

vultr.guest systemd[1]: Started MySQL Community Server.
vultr.guest mysqld[17740]: warning: cannot open /etc/hosts.allow: Permission denied
vultr.guest mysqld[17740]: warning: cannot open /etc/hosts.deny: Permission denied
vultr.guest mysqld[17740]: refused connect from ::1

Right. So I check the hosts files and their permissions are set to 774, which realistically shouldn't pose any issue. I up the permission to 777 for sake of science and it doesn't seem to make any difference. At this point I'm somewhat at a standstill as I can't find any other leads as to what might be the issue. For the most part all of the configuration is default for PHP and MySQL at the moment, so I honestly can't think of any potential discrepancies arising from their configuration. Anyone willing to share their thoughts on this?

share|improve this question

migrated from webmasters.stackexchange.com 21 hours ago

This question came from our site for pro webmasters.

    
What is your PHP script's connection configuration? – Dai 21 hours ago
    
What operating system you have ?? exactly ? can you show the output of ls -l /etc/hosts.* also Do you have selinux enabled and in enforcing mode? What permission is on the /etc directory entry itself? Are there any messages logged in /var/log/messages relating to the problem? – Maciej Cygan 20 hours ago
    
This is just a standard installation of Ubuntu server 15.10. The hosts files are definitely all there and correct. -rwxrwxr-- 1 root root 92 Feb 20 2014 /etc/host.conf -rwxrwxr-- 1 root root 12 Mar 9 11:18 /etc/hostname -rwxrwxr-- 1 root root 210 Nov 24 22:16 /etc/hosts -rwxrwxrwx 1 root root 0 Mar 9 19:24 /etc/hosts.allow -rwxrwxrwx 1 root root 0 Mar 9 19:24 /etc/hosts.deny I never installed selinux, so that's a no unless it came by default in Ubuntu server. /etc is 774. /var/log/mysql/error.log reports nothing about this. This comment has horrible formatting, sorry. – Pecon 12 hours ago

From your log it looks like the connection is made but rejected by mysqld, so this is probably neither a port-issue nor firewall-related.

As far as I know, If you use the command line client to make a connection to a server on localhost, the client always makes the connection through the socket file. PHP on the other hand probably uses TCP/IP.

Maybe there's an error (or some special security measure) in your mysqld configuration that has your mysqld listening on a port but rejects all TCP/IP connections.

share|improve this answer
    
I don't think this is the problem – Maciej Cygan 20 hours ago
    
I've double checked all the mysql config files in /etc/mysql and have not found anything that isn't entirely default. I am especially confused as to why the server is complaining that it doesn't have access to the hosts files, since they should be 100% accessible. As far as I can tell, it's denying the connection because it can't access the host rules as a sort of failsafe. But there shouldn't be any reason that it can't access them whatsoever. – Pecon 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.