If you are getting the "Fatal error: Call to undefined function imap_open()" error in PHP when using the IMAP functions then they are not installed with your installation of PHP. This post looks at how to install the PHP IMAP functions on Debian and should also work for Ubuntu/Kubuntu/etc and other Debian derived Linux distros.
I have previously posted about this for CentOS/RHEL/Fedora and have added this post because the command to install PHP IMAP is different for Debian, and I’ve recently moved from CentOS with PHP 5.1.6 to Debian with PHP 5.2.6.
To install the PHP IMAP extension on Debian, run the following from the command line either as root or using the sudo command:
aptitude install php5-imap
You’ll see something along the lines of 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/?]
Type in "y" and then <enter> and you’ll see something along the lines of this:
Writing extended state information... Done Get:1 http://ftp.nz.debian.org lenny/main mlock 7:2007b~dfsg-4+lenny3 [30.8kB] Get:2 http://ftp.nz.debian.org lenny/main libc-client2007b 7:2007b~dfsg-4+lenny3 [772kB] Get:3 http://ftp.nz.debian.org lenny/main php5-imap 5.2.6.dfsg.1-1+lenny2 [38.1kB] Fetched 841kB in 2s (322kB/s) Selecting previously deselected package mlock. (Reading database ... 19854 files and directories currently installed.) Unpacking mlock (from .../mlock_7%3a2007b~dfsg-4+lenny3_amd64.deb) ... Selecting previously deselected package libc-client2007b. Unpacking libc-client2007b (from .../libc-client2007b_7%3a2007b~dfsg-4+lenny3_amd64.deb) ... Selecting previously deselected package php5-imap. Unpacking php5-imap (from .../php5-imap_5.2.6.dfsg.1-1+lenny2_amd64.deb) ... Processing triggers for man-db ... Setting up mlock (7:2007b~dfsg-4+lenny3) ... Setting up libc-client2007b (7:2007b~dfsg-4+lenny3) ... Setting up php5-imap (5.2.6.dfsg.1-1+lenny2) ... Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Writing extended state information... Done Reading task descriptions... Done
You’ll be able to immediately access the IMAP functions from the command line interface but will need to gracefully restart Apache to access the functions in your web based scripts by running the following either as root or using the sudo command:
Now you should be able to use the PHP IMAP functions.