I've tried every way to install imap php extension but I couldn't do it. I am using amazon web service EC2 instance and it has CentOS. while yum search *-imap.* I found a package from cyrus-imap.* but it's not working. I've installed it but it seems to be not the package I want. I have tried many things but there are no package with php-imap on cent os.

My application badly needs php-imap extension. My php config

# php -v 
PHP 7.2.31 (cli) (built: Jul  2 2020 23:17:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Can anyone help? Thanks in advance.

  • Give the article linked above a go. It has pretty clear instructions. If it doesn't work hit the "reopen" link and let us know why the other answer didn't work :)
    – Tim
    Sep 3, 2020 at 7:40
  • Thank you for suggesting the answer but it isn't helping, well i've tried that but its not working. the problem is on my ec2 linux 2 ami can't even install the epel release so my problem is getting worse. Sep 3, 2020 at 9:23
  • But thanks anyway i got a solution here it is found it on This link Basically i had to install the epel-release after i installed some extra things 1 - sudo yum groupinstall "Development Tools" 2 - sudo amazon-linux-extras install epel 3 - yum install epel-release 4 - sudo yum install libc-client-devel uw-imap-static openssl-devel Sep 3, 2020 at 9:28
  • The rest of the instructions are on the link. the main problem is solved now it can be easily solved Sep 3, 2020 at 9:35
  • Beware: EPEL is not guaranteed to be compatible with Amazon Linux or Amazon Linux 2. Packages you install from EPEL onto Amazon Linux (2) may not work correctly, or may not be installable, or may stop working in the future. It is irresponsible for Amazon to keep offering it the way they do. If you need packages from EPEL, you should run CentOS or RHEL instead of Amazon Linux. Sep 3, 2020 at 14:27

1 Answer 1


The main problem with imap is that this package is not available as php-imap on amazon linux 2 so we need to choose some alternative way. The main problem is to configure the essential files that are needed to build the imap setup files. So the total procedure is two steps.

  • One is to setup the development tools.
  • Two is to build imap from the setup files.

Follow my instructions as given below

  • sudo yum groupinstall "Development Tools"
  • install epel realese sudo amazon-linux-extras install epel and then yum install epel-release
  • install some dependencies sudo yum install libc-client-devel uw-imap-static openssl-devel
  • Create the symlink sudo ln -s /usr/lib64/libc-client.a /usr/lib
  • Now download the full php files from the official php website. We will be needing the core files to build the imap extensions. Go to your root folder by cd~ then wget https://www.php.net/distributions/php-7.x.x.tar.gz
  • Untar the tar.gz: tar -xf php-7.x.x.tar.gz
  • Now go to the directory
cd php-7.x.x/ext/imap
./configure --with-kerberos --with-imap-ssl
  • Go to the modules folder and type cd php-7.x.x/ext/imap/modules
  • sudo cp imap.so /usr/lib64/php/modules/
  • Then open with nano sudo nano /etc/php.d/30-imap.ini and write extension=imap
  • Restart httpd or php fmp sudo systemctl restart php-fpm and sudo systemctl restart httpd
  • Done. You can view it by typping php -m | grep imap it will show imap in red font. Done TIA
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Sep 13, 2020 at 4:54
  • Okay i am editing it. Sep 13, 2020 at 5:24
  • Thank you it works :) Feb 8, 2021 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.