Building your own PHP with IMAP support is not that hard, but i noticed a lot of people tend to have problems when they want SSL support in it.
You might run into stuff like this (when reconfiguring php f.e.):
configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
First things first, .. forget all the posts and manuals you read about downloading imap-2007e.tar.gz and what not and just do the following.
aptitude install libc-client-dev
yum install libc-client-devel
Then run your php configure again with:
./config.nice --with-imap --with-imap-ssl --with-kerberos
Then continue installing php like you always do.