I recently ran into a problem where I started to get a “Fatal error: Call to undefined function imap_open()” error in PHP when using the IMAP functions. This is a quick post to tell more novice Debian users (like me) how to install the PHP IMAP extension. This stuff should also work for Ubuntu and other Debian derived Linux distributions.
The command to install PHP IMAP is different for Debian than other systems like CentOS or Fedora. To install the extension simply run the following command as root or using the sudo command:
aptitude install php5-imap
You should then see something like this:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Reading task descriptions… Done
The following NEW packages will be installed:
libc-client2007b{a} mlock{a} php5-imap
0 packages upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 841kB of archives. After unpacking 1810kB will be used.
Do you want to continue? [Y/n/?]
Then simply answer “y” and then press ENTER.
You should then be able to immediately access the IMAP functions from the command line. To access the commands from web based scripts you need to gracefully restart Apache, to do this run the following command from root or using the sudo command:
apache2ctl graceful
OR
/usr/sbin/apache2ctl graceful
You should now be able to use PHP IMAP functions.
