# Problems with hostname resolution



## balanga (Jul 31, 2014)

Over the last week I've been struggling to get Wordpress running on FreeBSD. I finally managed to get it working yesterday after much trial and error and I'm still not sure how well it is installed and configured but at least it does work, using the latest FreeBSD, Apache2, MySQL and Wordpress. I did find in the course of my struggle that installing packages was more successful than using ports.

Anyway, my query.: in the Wordpress configuration file wp-config.php I needed to define DB_HOST as 192.168.1.107  i.e. the IP address of the server I'm running, for Wordpress to be able to connect to MySQL. Definitions of 127.0.0.1 or 'localhost' would not work. 

This may not be the appropriate forum to pose this question but the level of knowledge here is vast so someone may be able to help me. How can I tell how the hostname is resolved? I.e. where do I look? I do have hostname defined in /etc/rc.conf but that does not seem to apply to Wordpress, so Wordpress must be picking it up from either Apache or MySQL. Any ideas where to look?


----------



## usdmatt (Jul 31, 2014)

If Wordpress is configured to use an IP address for the database host, then it has nothing to do with hostname resolution.

localhost almost certainly resolves to 127.0.0.1 unless you've messed with something, so using either of those will do exactly the same thing.
The name -> IP resolution for localhost is done in /etc/hosts.

If you want server.hostname to resolve to 192.168.1.107 without resorting to DNS, the just add that to /etc/hosts using the other entries already in there as an example. You can test local name resolution fairly simply by just running `ping some.name`.

If Wordpress will connect to MySQL using 192.168.1.107, but not 127.0.0.1, this is almost certainly down to MySQL configuration. Either your MySQL server is configured to listen only on the 192 address, or the MySQL user account you are using does not have permission to access the database from localhost. (Note that in a default MySQL install, adding a user with access from '%' (all hosts) doesn't actually work for localhost. You have to add a second user entry specifically for localhost access).


----------



## balanga (Jul 31, 2014)

usdmatt said:
			
		

> If Wordpress will connect to MySQL using 192.168.1.107, but not 127.0.0.1, this is almost certainly down to MySQL configuration. Either your MySQL server is configured to listen only on the 192 address, or the MySQL user account you are using does not have permission to access the database from localhost.



Assuming that MySQL is misconfigured how do I change it?

I have just noticed a file /var/db/mysql/Balanga.err (Balanga is my hostname in /etc/rc.conf) which contains the lines

```
2014-07-29 12:10:21 14661 [Note] Server hostname (bind-address) '*': port: 3306
2014-07-30 14:42:46 14661 [Warning] IP address '192.168.1.107' could not be resolved: hostname nor servname provided, or not known
```


----------



## usdmatt (Jul 31, 2014)

Seems like MySQL is set to listen on all addresses/interfaces.
If it's not configured to allow connections for your Wordpress user from localhost, the easiest thing is to run the following:


```
grant all on dbname.* to username@localhost identified by 'password'
```

Then use localhost/127.0.0.1, and the username/password above in Wordpress. If you only need this user to access from localhost, then you can delete any entries in mysql.user/mysql.db for this username before running the above command, so the account can't be used remotely.


----------

