localhost and 127.0.01 - weird behaviour

hetch

Active Member
Feb 4, 2009
28
0
51
I use in my php scripts configuration files 'localhost' to get connected to the database. Works fine.

But the in same script > mail settings > I can not use 'localhost' to sent email. Getting this error:

0.66544400 1379291101 15-09-2013 19:25:01 (3)Mailer - [pear_error: message="unable to connect to smtp server localhost:25" code=0 mode=return level=notice prefix="" info=""]

If I change 'localhost' to '127.0.01' in mail settings , it works. Email will be sent?

I didn't change any whm/cpanel settings. Anybody throw some light on this?

thank you!
 

24x7server

Well-Known Member
Apr 17, 2013
1,912
99
78
India
cPanel Access Level
Root Administrator
Twitter
It is one and the same you can either use localhost or loop back IP address that is 127.0.0.1 for your mail sending script.

So not sure if this change will work for you. I would better suggest you to check why your server is not able to connect to port 25 through loop back port.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
Hello :)

Yes, I have seen this behavior before. It typically happens because the /etc/hosts file is not available to the account. Thus, connections to 'localhost' (which can't resolve to 127.0.0.1) will fail. Using 127.0.0.1 is a valid workaround to this issue.

Thank you.
 

hetch

Active Member
Feb 4, 2009
28
0
51
It typically happens because the /etc/hosts file is not available to the account.
1. It supposed to be available to the user account by default?

2. What I need to tell the host to fix this?

thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
You can direct your web hosting provider to the following URL:

Custom JailedShell Mounts

One additional workaround has been to add /etc/hosts to a file that is sourced such as:

/var/cpanel/exim.conf.deps

Thank you.
 

hetch

Active Member
Feb 4, 2009
28
0
51
/var/cpanel/exim.conf.deps
My host went with this option.

But my questions:

Can this settings can be done thru WHM? If yes, how?

With each cpanel update, this seting will be over written?

thank you!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,267
463
My host went with this option.

But my questions:

Can this settings can be done thru WHM? If yes, how?

With each cpanel update, this seting will be over written?
The setting can not be modified via Web Host Manager, and should not be overwritten during cPanel updates. Could you confirm if that modification resolved the issue?

Thank you.
 

hetch

Active Member
Feb 4, 2009
28
0
51
Could you confirm if that modification resolved the issue?
Yes. '/var/cpanel/exim.conf.deps' resolved the issue. I am able to use localhost again.

Thank you.