How to Setup a Complete Mail Server (Postfix) using ‘SquirrelMail’ (Webmail) on Ubuntu/Debian

Creating a mail server on Linux powered machines can be one of the most essential things that every system administrator needs to do while configuring his servers for the first time, if you don’t know what it means; it’s simple, if you have a website like “”, you can create an email account like “[email protected]” to use it to send / receive emails easily instead of using services like Hotmail, Gmail, Yahoo Mail, etc.

Setup Postfix Mail Server in Debian

Setup Postfix Mail Server in Ubuntu/Debian

In this article, we’ll learn how to do so by installing the Postfix with “SquirrelMail” webmail application and its dependencies on Debian/Ubuntu machines.

Step 1: Installing Apache2 and PHP7

1. In order to create a running mail server using “SquirrelMail”, we’ll have to install both Apache2 & PHP7 packages first, to do so, run.

$ sudo apt-get update -y
$ sudo apt-get upgrade -y
$ sudo apt-get install apache2 php7
Install Apache and PHP

Install Apache and PHP

Step 2: Installing Postfix Mail Server

2. Postfix is a mail transfer agent (MTA) which is the responsible software for delivering & receiving emails, it’s essential in order to create a complete mail server.

To install it on Ubuntu/Debian or even Mint, run:

$ sudo apt-get install postfix

During installation, you will be asked to choose the type of mail configuration, choose “Internet Site”.

Install Postfix in Ubuntu

Install Postfix in Ubuntu

3. Now enter the fully qualified domain name that you want to use for send and receive mails.

Set Postfix Mail Domain

Set Postfix Mail Domain

4. Once the FQDN set, you’ve restart the Postfix mail server using.

$ sudo service postfix restart
Start Postfix Mail Server in Ubuntu

Start Postfix Mail Server in Ubuntu

Step 3: Installing Dovecot

5. Dovecot is a mail delivery agent (MDA), it delivers the emails from/to the mail server, to install it, run the following command.

$ sudo apt-get install dovecot-imapd dovecot-pop3d
Install Dovecot in Ubuntu

Install Dovecot in Ubuntu

6. Next, restart Dovecot service using the following command.

$ sudo service dovecot restart
Start Dovecot in Ubuntu

Start Dovecot in Ubuntu

Step 4: Installing SquirrelMail in Ubuntu

7. SquirrelMail is the email server that you’ll be using to manage emails on your server, it has a simple web interface to do the job, it can be customized by installing more modules & themes.

$ wget
$ unzip
$ sudo mv squirrelmail-webmail-1.4.22 /var/www/html/
$ sudo chown -R www-data:www-data /var/www/html/squirrelmail-webmail-1.4.22/
$ sudo chmod 755 -R /var/www/html/squirrelmail-webmail-1.4.22/
$ sudo mv /var/www/html/squirrelmail-webmail-1.4.22/ /var/www/html/squirrelmail

8. After the installation, you will have to run this command in order to configure SquirrelMail.

$ sudo perl /var/www/html/squirrelmail/config/
Configure Squirrelmail in Ubuntu

Configure Squirrelmail in Ubuntu

09. Next, enter “2” in order to edit the server settings, and you will be prompted to it.

Squirrelmail Server Settings

Squirrelmail Server Settings

10. Now enter “1” in order to change the domain name and write up your domain (e.g:

Set Mail Domain

Set Mail Domain

11. Go back to the main menu by writing “R” and hitting the enter key, write “4” in order to configure the general options.

You see “Allow server-side sorting”? Enter “11” and change it from “false” to “true” by entering “y”. Now hit the Enter key, and enter the “S” key in order to save the configuration file.

Configure General Mail Options

Configure General Mail Options

12. You can now access the mail server by going to

Access Squirrelmail in Ubuntu

Access Squirrelmail

Step 5: Creating Mail Users

13. In order to start using squirrelmail webmail, you’ll have to create a new user, to do so, run.

$ sudo useradd myusername

Replace “myusername” with the user name you want, create a password for the new user by running.

$ sudo passwd myusername

14. Create a home folder for the user in /var/www/html/myusername and make it default home directory.

$ sudo mkdir -p /var/www/html/myusername
$ usermod -m -d /var/www/html/myusername myusername

15. Now go back to the login page and enter the user name and the password of newly created user.

Access Squirrelmail in Ubuntu

Access Squirrelmail

You will be surprise to see the following error message.

Login to Squirrelmail

Login to Squirrelmail

This is just a problem in the permissions, you have to give the user “myusername” the complete permissions on its home folder.

$ sudo chown -R myusername:myusername /var/www/html/myusername

16. Once permission set, you should able to login into squirrelmail.

Squirrelmail Mail Interface

Squirrelmail Mail Interface

You can try to send email from it, or you can try to receive emails by sending it to “[email protected]” , don’t forget to replace “myusername” with the user name you created.

If you faced any other error.. Just check the “/var/log/mail.err” file, all the error message will be stored there, you won’t lose your way :)

Have you tried to create an email server before? How did it go? Have you used SquirrelMail or any other mail server before? What do you think about it?

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

221 Responses

  1. Dany says:

    Hello, I have a question.

    I don’t own a domain yet. But I wanted to know if it is possible to create a free domain such as “” and send emails from it? Or is it required of me to purchase the domain first?

  2. Le Minh Quan says:

    ERROR: Config file ‘ . ‘”config/config.php” not found. You need to ‘ . ‘configure SquirrelMail before you can use it.
    ‘; exit; } // If we are, go ahead to the login page. header(‘Location: src/login.php’); ?>

  3. Dameats says:

    In step 14 this command usermod -m -d /var/www/html/myusername myusername is not working for me says user mod no changes.
    anyway, I’m able to log in to the error screen.
    then i use command sudo chown -R myusername:myusername /var/www/html/myusername and still get the IMAP error.

    (I’m supposed to replace my username in any of this for my actual user name ?) I’ve tried also not working.

    your help is greatly appreciated

  4. Muhammad Usman says:

    I have completed all steps and even I remove all folder and repeat all steps carefully still I faced error:

    Error opening ../data/default_pref
    Could not create an initial preference file!
    /var/local/squirrelmail/data/ should be writable by user www-data

    Please contact your system administrator and report this error.

    • Ravi Saive says:


      Make the following directory writable by user www-data.

      $ sudo chown -R www-data:www-data /var/local/squirrelmail/data/
      $ sudo chmod -R 776 /var/local/squirrelmail/data/
      • Muhammad Usman Sarwar says:

        Thank you so much, Sir,

        If I want to generate an email from laravel or python Django. How I will set laravel mail setting or Django?

        MAIL_DRIVER=smtp ------> what type here
        MAIL_PORT=2525   ------> port number ?

        and can you send me some tutorial or documentation of its? I am very thankful to you…

  5. James says:

    I have installed Squirrelmail as per your provided instructions. However, when I connect using Firefox I get a blank page.

    Using Chromium I get connection refused by the server.

  6. MZ says:

    Login page isn’t opening for me. I have followed all the instructions. I cant access the login page. PLEASE HELP

  7. Cooper says:

    Hello Sir,

    I have followed your instruction to create the web server. But I can’t log in with the user I created and even root. I am using a virtual host. how can I create email user on the virtual host?

  8. TechNafo says:

    Error opening ../data/default_pref
    Could not create initial preference file!
    /var/local/squirrelmail/data/ should be writable by user www-data.

    Please contact your system administrator and report this error.

    I get this error and /var/local/squirrelmail/data is not exist.

    • John says:

      What I did was that I copied “squirrelmail” folder that is in /var/www/html/squirrelmail copied to /var/local and did the permissions again, I dont know if I did it right or not but it seems to be working for me after doing that, correct if I am wrong @Ravi Saive

      • Ravi Saive says:


        As per the instructions provided here, the step 4 clearly shows that squirrelmail installed under /var/www/html/squirrelmail and the data directory would be /var/www/html/squirrelmail/data.

    • Ravi Saive says:


      Please follow the Step 4: Installing SquirrelMail in Ubuntu properly…

      • John says:

        But Step 4 does not talk about directory /var/local/ at all

        • Ravi Saive says:


          Then, where you have installed your Squirrelmail? as per step 4 it will install under /var/www/html and data directory would be /var/www/html/squirrelmail/data.

          • John says:

            I followed step 4 and I ended up with a folder “squirrelmail” in /var/www/html/ because I was having that error I mentioned before, all that I did was copy that folder “squirrelmail” to /var/local then I ran the commands again for permissions and that was it, it was fixed for me, I dont know if I was supposed to manually copy the folder to /var/local or not but I did.

  9. John says:

    I am following all the steps but I am getting this error message at the end after giving full permissions.

    Error opening ../data/default_pref
    Could not create initial preference file!
    /var/local/squirrelmail/data/ should be writable by user www-data
    Please contact your system administrator and report this error.

    I checked mail.err but nothing in there

    • Ravi Saive says:


      Make the following directory writable by user www-data.

      # chown -R www-data:www-data /var/local/squirrelmail/data/
      # chmod -R 776 /var/local/squirrelmail/data/
  10. tcullen says:

    It would appear that these directions are out of date or there is a repository that should be perhaps be mentioned where php5 can be obtained from.

    [email protected]:~$ sudo apt-get install apache2 php5
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package php5 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    E: Package 'php5' has no installation candidate
    • Ravi Saive says:


      I’ve updated the article and included latest instructions for setting up complete mail server using Postfix on Ubuntu.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.