php-imap package is not available neither in Red Hat Enterprise Linux 7 nor 8.
To compile the extension yourself:
Prerequisites
# yum install pam-devel openssl-devel
Follow steps 2 and 3 from the previous post of "ldi at email dot cz"
Download the c-client library from github, you can see the link at the top of the page and compile with:
# make lr5 SSLINCLUDE=/usr/include/openssl/ EXTRACFLAGS=-fPIC
(if you are using another distro, instead of lr5 you will type something else, you can view the Makefile for other unix flavors)
Follow step 5 from the previous post of "ldi at email dot cz" which is what the second paragraph at the top of the page explains.
Download the PHP source code of the version installed in your system and go to the php/ext/imap folder.
# phpize
(If you installed the PHP packages from the Red Hat Software Collections you must run the following command before to set the enviroment eg: scl enable rh-php73 bash)
# ./configure --with-imap=<<path_to_where_you_unpacked_the_c-client_library_and_compiled_it>> --with-imap-ssl
# make
This creates the file php/ext/imap/modules/imap.so :)
Copy it to your extension_dir (you can find it in the phpinfo() page).
Create an .ini file in the php.d folder with the text: extension=imap.so
Restart apache and be happy.
P.S. You could probably find the extension compiled out there but who knows the trustiness of the source so better to get the official unaltered sources.