How to enable IMAP php extension on aws EC2 instance

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.


Solution 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
phpize
./configure --with-kerberos --with-imap-ssl
make
  • 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