The Installation Procedure is always the same, but the package-manager and package-name varies, depending which distribution, version and/or repository one uses. In general, the steps are:
a) at first, user privilege escalation is required, either obtained with the commands su or sudo.
b) then one can install the absent PHP module with a package manager.
c) after that, restarting the apache2 HTTP daemon is required to load the module.
d) at last, one can run php -m | grep imap to see if the PHP module is now available.
On Ubuntu the APT package php5-imap (or php-imap) can bei installed with apt-get:
apt-get install php5-imap
service apache2 restart
On Debian, the APT package php5-imap can be installed aptitude (or apt-get):
aptitude install php5-imap
apache2ctl graceful
On CentOS and Fedora the RPM package php-imap can be installed with yum (hint: the name of the package might be something alike php56w-imap or php71w-imap, when using Webtatic repo):
yum install php-imap
service httpd restart
On systemd systems, while using systemd units, the command to restart unit httpd.service is:
systemctl restart httpd.service
The solution stated above has the problem, that when the module was already referenced in:
/etc/php5/apache2/php.ini
It might throw a:
PHP Warning:  Module 'imap' already loaded in Unknown on line 0
That happens, because it is referenced in the default php.ini file (at least on Ubuntu 12.04) and a PHP module must at most be referenced once. Using INI snippets to load modules is suggested, while the the directory /etc/php5/conf.d/ (that path may also vary) is being scanned for INI files:
/etc/php5/conf.d/imap.ini
Ubuntu also features proprietary commands to manage PHP modules, to be executed before restarting the web-server:
php5enmod imap
php5dismod imap
Once the IMAP module is loaded into the server, the PHP IMAP Functions should then become available; best practice may be, to check if a module is even loaded, before attempting to utilize it.