Open In App
Related Articles

How to Install imap extension in PHP on Linux?

Improve Article
Save Article
Like Article

The Internet Message Access Protocol (IMAP) is an application layer protocol that allows a client to efficiently access emails from anywhere. It stores email on the server and can download on-demand. It is like an intermediary between client and email servers. It was designed by Mark Crispin in 1986 as a remote access mailbox protocol and the current version of IMAP is IMAP4.

Advantages of IMAP:

  • Access: Whenever you are accessing mails using IMAP, you are directly accessing mails from email servers. Hence, you can manage and access mails and mail folders from any computer or mobile phone.
  • IMAP uses fetch technology, so when a new email arrives email client automatically fetches new mails at specified intervals.
  • Server-side searches: IMAP4 provides a feature for the client to ping the server to search for the mail using various searching criteria.

Disadvantages of IMAP:

  • IMAP4 clients need to maintain a TCP/IP connection with the IMAP server to receive the notification of the new mails.
  • Unless mail storage and server search algorithms are carefully implemented, a customer may potentially consume large quantities of server resources when searching for massive mailboxes.
  • It can be complex to maintain due to which some host does not support the protocol. It also required the drive space of the host to perform the operation.

Verify PHP IMAP installation on Linux

To verify your installation, follow the following steps:

Step 1: Open a terminal and change your directory to the webroot folder using the following command:

cd /var/www/html/


Step 2: Create a file with any name with the extension .php using any editor. I am using nano here. Also, avoid using “phpinfo” as a file name.

sudo nano whatever.php


Step 3: Write the following code in the file “whatever.php”





Step 4: Hit Ctrl+x, then respond with “Y” for yes, then press the ENTER button. 


Step 5: Run the command ifconfig in the terminal and copy the URL.


Step 6: Open a Web browser and paste the URL along with “whatever.php” at the end. URL should look like this



Look for the file named “/etc/php/7.4/apache2/conf.d/20-imap.ini”. If it is present IMAP extension is already installed. Otherwise, follow the steps below.


Installing PHP IMAP on Linux

To install the IMAP extension, perform the following steps:

Step 1: Enter the following commands in the terminal to install the IMAP extension for any PHP version on Linux

sudo apt install php-imap


Step 2: Enable PHP IMAP extension using the following command:

sudo phpenmod imap           


Step 3: Restart the Apache server using the following command:

sudo systemctl restart apache2 


Step 4: Verify IMAP installation again.



Hence, this is how we install the PHP IMAP extension in Linux.

Last Updated : 31 Jan, 2022
Like Article
Save Article
Similar Reads
Related Tutorials