Matthew Sielski
Matthew Sielski

Reputation: 847

PHP imap_open fails via Apache with "no such host" but works at command line

I am using PHP 5.3.10 on CentOS 5.8. PHP has been built from source with this config:

./configure --enable-gd-native-ttf --enable-mbstring \
  --enable-sockets --with-bz2 --with-curl --with-gd --with-mcrypt \
  --with-mysql --with-mhash --with-mysqli --with-openssl --with-pdo-mysql \
  --with-pear --with-pcre-regex --with-xsl --with-zlib --with-libdir=/lib64 \
  --with-imap --with-kerberos --with-imap-ssl --with-apxs2=/usr/sbin/apxs

I am positive there are no other versions of PHP on the system, and I've confirmed that through the browser and CLI that the imap extension is available.

This issue is affecting a CMS I'm using, but to test I used a simple PHP script, which is:

<?php
error_reporting(15);

$username = "username";
$password = "password";

$mailserver = "{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX";

$link = imap_open($mailserver, $username, $password, NULL, 1);
print_r(imap_errors());

$headers = imap_headers($link);
print_r($headers);
?>

When I run this at the command line I get the expected output which is no error messages and a list of the messages in the inbox.

When I point a browser to the test script I get:

Warning: imap_open() [function.imap-open]: Couldn't open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX in test.php on line 9
Array ( [0] => No such host as pop.gmail.com ) 

and then additional warnings as imap_headers fails.

Clearly the imap extension is available via Apache and CLI, and this shouldn't be a firewall or DNS issue as it does work from the CLI. I can also telnet to the mail server.

I am using the default php.ini-development file (a copy is here) and confirmed with phpinfo() and php -i that it's in use by both environments.

Does anyone have any ideas why imap_open would come back with "no such host as..." through Apache but not at the command line?

edit:

I am using libc-client and libc-client-devel version 2004g-2.2.1 and httpd 2.2.3-63.el5.centos.1 from the stock CentOS yum repos

Upvotes: 0

Views: 3040

Answers (1)

Matthew Sielski
Matthew Sielski

Reputation: 847

I forgot that Apache was using mod_chroot and apparently access to the library providing DNS was blocked. I had to add LoadFile /lib64/libnss_dns.so.2 to my httpd.conf, thanks to this page.

Upvotes: 0

Related Questions