Install the PHP IMAP extension
The IMAP extension provides functions for using the IMAP and POP3 protocols.
For PHP 5.6 through PHP 8.3, the IMAP extension is installed by default. You do not need to install the IMAP extension for these PHP versions.
Starting with PHP 8.4, the IMAP extension was removed from PHP and must be installed as a third-party extension using the instructions below.
Install the IMAP extension
Installing the extension involves the following steps:
- Install build dependencies (packages that are required to build the extension).
- Build the extension’s library file.
- Enable the extension in the PHP configuration.
Install build dependencies
Set environment variables for the package manager.
export DEBIAN_FRONTEND=noninteractiveInstall a compiler and other packages that are required for building PHP extensions.
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-configInstall additional packages that are required to build the IMAP extension.
sudo apt-get -y install libkrb5-dev libc-client-dev libssl-devBuild the extension
The PECL install command compiles the extension’s .so library file.
yes '' | sudo pecl8.5-sp install imapyes '' | sudo pecl8.4-sp install imapEnable the extension
Configure PHP to load the extension.
sudo bash -c "echo extension=imap.so > /etc/php8.5-sp/conf.d/imap.ini"sudo bash -c "echo extension=imap.so > /etc/php8.4-sp/conf.d/imap.ini"Restart PHP-FPM.
sudo service php8.5-fpm-sp restartsudo service php8.4-fpm-sp restartVerify the extension is enabled in PHP.
php8.5-sp -i | grep imapphp8.4-sp -i | grep imapIf the extension is enabled, you will see output like the following.
/etc/php8.4-sp/conf.d/imap.ini,Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftpimapimap.enable_insecure_rsh => Off => OffUninstall the IMAP extension
Uninstalling the extension involves the following steps:
- Disable the extension in the PHP configuration.
- Remove the extension’s library file.
Disable the extension
Remove the extension’s configuration from PHP.
sudo rm /etc/php8.5-sp/conf.d/imap.inisudo rm /etc/php8.4-sp/conf.d/imap.iniRestart PHP-FPM.
sudo service php8.5-fpm-sp restartsudo service php8.4-fpm-sp restartRemove the extension
The PECL uninstall command removes the extension’s .so library file.
sudo pecl8.5-sp uninstall imapsudo pecl8.4-sp uninstall imap