Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
127.0.0.1 vs localhost for phpmyadmin and Wordpress
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
ferg
Guru
Guru


Joined: 15 Nov 2002
Posts: 536
Location: Cambridge, UK

PostPosted: Mon Feb 22, 2016 3:09 pm    Post subject: 127.0.0.1 vs localhost for phpmyadmin and Wordpress Reply with quote

Hi,

I've a Gentoo development server that I've not really been keeping on top of!

I just had a confusing error with Wordpress that couldn't connect to my database. I launched phpmyadmin to test the PHP > MYSQL connection and that could not work either.

Turns out that for both tools I needed to connect to "127.0.0.1" instead of "localhost". So editing the appropriate config files restored functionality.

Has anything like that changed recently? Like in the past six months?

Cheers
Ferg
_________________
Climb up it, kayak down it + make sure it runs on GNU/Linux
"cease to exist, giving my goodbye, drive my car into the ocean,
you think I'm dead, but i sail away, on a wave of mutilation!"
Back to top
View user's profile Send private message
ct85711
Veteran
Veteran


Joined: 27 Sep 2005
Posts: 1791

PostPosted: Mon Feb 22, 2016 9:39 pm    Post subject: Reply with quote

Typically, 127.0.0.1 is linked to localhost so it would work, however, the link is typically set inside the /etc/hosts file. You may want to check that file, here's a copy of my hosts file (most times peopkle rarely need to modify the file).

Code:
# /etc/hosts: Local Host Database
#
# This file describes a number of aliases-to-address mappings for the for
# local hosts that share this file.
#
# In the presence of the domain name service or NIS, this file may not be
# consulted at all; see /etc/host.conf for the resolution order.
#

# IPv4 and IPv6 localhost aliases
127.0.0.1   localhost
::1      localhost

#
# Imaginary network.
#10.0.0.2               myname
#10.0.0.3               myfriend
#
# According to RFC 1918, you can use the following IP networks for private
# nets which will never be connected to the Internet:
#
#       10.0.0.0        -   10.255.255.255
#       172.16.0.0      -   172.31.255.255
#       192.168.0.0     -   192.168.255.255
#
# In case you want to be able to connect directly to the Internet (i.e. not
# behind a NAT, ADSL router, etc...), you need real official assigned
# numbers.  Do not try to invent your own network numbers but instead get one
# from your network provider (if any) or from your regional registry (ARIN,
# APNIC, LACNIC, RIPE NCC, or AfriNIC.)
#
Back to top
View user's profile Send private message
ferg
Guru
Guru


Joined: 15 Nov 2002
Posts: 536
Location: Cambridge, UK

PostPosted: Mon Feb 22, 2016 9:45 pm    Post subject: Reply with quote

Pinging "localhost" still works!
_________________
Climb up it, kayak down it + make sure it runs on GNU/Linux
"cease to exist, giving my goodbye, drive my car into the ocean,
you think I'm dead, but i sail away, on a wave of mutilation!"
Back to top
View user's profile Send private message
py-ro
Veteran
Veteran


Joined: 24 Sep 2002
Posts: 1734
Location: Velbert

PostPosted: Tue Feb 23, 2016 8:01 am    Post subject: Reply with quote

localhost has a special meaning for MySQL (and its drivers), rather connecting via lo, it does connect via a Unix socket, if localhost as server is specified.
Back to top
View user's profile Send private message
ferg
Guru
Guru


Joined: 15 Nov 2002
Posts: 536
Location: Cambridge, UK

PostPosted: Tue Feb 23, 2016 8:11 am    Post subject: Reply with quote

py-ro wrote:
localhost has a special meaning for MySQL (and its drivers), rather connecting via lo, it does connect via a Unix socket, if localhost as server is specified.


That makes sense. So my problem was likely that there was a problem connecting via a UNIX socket and I've inadvertently worked around that:

PHP (i.e. PHPmyAdmin and Wordpress) were previously connecting via a UNIX socket. That broke (perhaps the dir change to "/run/mysql/mysqld.sock"?). Changing from "localhost" to "127.0.0.1" forced PHP to connect via TCP/IP instead. Thus working around the socket problem.

So I should fix the socket problem I guess.
_________________
Climb up it, kayak down it + make sure it runs on GNU/Linux
"cease to exist, giving my goodbye, drive my car into the ocean,
you think I'm dead, but i sail away, on a wave of mutilation!"
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Tue Feb 23, 2016 9:28 am    Post subject: Reply with quote

ferg wrote:
So I should fix the socket problem I guess.


Yes, no maybe :)

Sockets are good if speed really really matters.
loopback interfaces have a stupid large MTU so there should be no/little fragmentation so the only overhead you have is that the packet still needs to traverse the whole network stack whereas a socket doesn't.
Sockets have acl by default (it's a file, so same semantics) whereas loopback has none.

On the other hand ......
loopback interfaces are generally better tested and it's easier to say another host instead of localhost if you need to spread the load across boxes.
I personally fine loopbacks easier to manage incase the local idiot (me on a bad day) hoses the socket file.
Also, the startup order of loopbacks is a lot more flexible (see socket activation issues in systemd and friends).
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum