I found while building the server, that although i could ping localhost successfully, in certain configuration files for services like Postfix and Apache and Dovecot, I needed to specify 127.0.0.1 instead of localhost in order to make them work.

I also needed to change the configuration files of certain database driven websites, which used localhost to connect to MySQL.

I've tried various modifications to the hosts file, but nothing I've tried so far has helped.

The server is running Ubuntu 12.04.02 LTS. It does not have selinux installed and the above situation remains even after setting IPtables default policies to accept and flushing them.

I've a feeling you're on the right track. I've done that and I can see that although root and couple of other users were created for localhost, those created by the hosting control panel for users are all for 127.0.0.1 (except for one which is %). I think this probably reveals enough for me to fix it, so I will probably accept your answer in short while.
–
Peter SnowOct 7 '13 at 3:54

Most MySQL clients are odd in the fact that if you specify the host as localhost, they alias that to a socket connection instead of a TCP connection. Your options are to either stick with 127.0.0.1 or, if the client supports it (like the mysql CLI binary does with the --protocol flag), force it to use TCP instead of a unix socket.

Thanks EEAA. The problem is that things like the Joomla installer fail. If the you specify 127.0.0.1 instead of localhost in the hostname field during installation, it causes installation paths to get messed up giving me other errors, but specifying localhost fails to connect the database! What's caused this situation? Why do I have it?
–
Peter SnowOct 7 '13 at 1:37

Thanks @MichaelHampton I've searched for the last half hour and can't find how to set up this. Can you point me at an article or give me some idea please? I do have socket = /var/run/mysqld/mysqld.sock in my.cnf and the file is existing, owned by mysql with permissions 777. Thanks.
–
Peter SnowOct 7 '13 at 2:51

@PeterSnow Did you restart mysqld after making that change?
–
EEAAOct 7 '13 at 3:13

Currently I'm trying to use it via the Joomla install script. The http page asks for the hostname. If I choose 127.0.0.1 it works (but the script uses the entry later and fails because it expects resolvable name like localhost), but if I use localhost, connecting, to create the database, fails.
–
Peter SnowOct 7 '13 at 3:19