Cannot Get IMAP Working - PHP5, Apache2 on Ubuntu


I have been trying to install and configure imap on my ubuntu server.

I log in as a root through Putty and then do the following:

sudo apt-get install php5-imap
Which now gives me:

Reading package lists… Done
Building dependency tree
Reading state information… Done
php5-imap is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Then a restart on the server:

apache2ctl graceful
After doing this I reload my PHPInfo file at and it still doesn’t show imap.

My IMAP script is

ini_set('display_errors', 1);

$imapHostname    = '';
$imapUsername    = '';
$imapPassword    = '******';

$imapConnection    = imap_open('\\{'.$imapHostname.'/imap}INBOX', $imapUsername, $imapPassword) or die('Connection to server failed');

$imapHeaders    = imap_headers($imapConnection) or die('Couldn\\'t get emails');

$imapNumEmails    = sizeof($imapHeaders);

echo 'You have '.$imapNumEmails.' in your mailbox';

and is located at and it still shows

Fatal error: Call to undefined function imap_open() in /home/testuser/domains/ on line 9

Any help would be gratefully appreciated.


I’m confused. I thought imap was for e-mail, not a web server. Okay, okay, PHP does have imap extensions but

It looks like you did something quite different (i.e., you did not recompile PHP).

I’m moving you to the server board for better help.



Disclaimer: I haven’t used php-imap extensions.

Try completely stopping Apache, and looking for any child processes that still might be running:

ps -waux | grep “apache”

Sometimes, a child process that won’t quit can hold up Apache from fully restarting.