How to Install SquirrelMail on Ubuntu 16.04 with LAMP or LEMP

SquirrelMail is an open source web-based mail client written in PHP with support for SMTP and IMAP protocol. In this tutorial we’re going to look at how to install SquirrelMail on a Ubuntu 16.04 VPS or dedicated server.

Prerequisites

In order to follow this tutorial, you need to have either LAMP or LEMP installed on your Ubuntu 16.04 machine. If you haven’t already done so, please check out the following guide.

SquirrelMail can be used to access your own email server as well as Gmail, hotmail etc.

Step 1: Install SquirrelMail on Ubuntu 16.04 from Repository

SSH into your Ubuntu 16.04 machine, update package index and install SquirrelMail, which is included in Ubuntu software repository.

sudo apt update
sudo apt install squirrelmail

/usr/share/squirrelmail/ directory will be the document root.

Step 2: Configure a Virtual Host for SquirrelMail

You can use either Apache or Nginx web server.

Apache

If you are using Apache web server, then copy the example config file (/etc/squirrelmail/apache.conf) to /etc/apache2/sites-available/ directory, at the same time rename it as squirrelmail.conf.

sudo cp /etc/squirrelmail/apache.conf /etc/apache2/sites-available/squirrelmail.conf

Open this file with nano text editor and make some changes.

sudo nano /etc/apache2/sites-available/squirrelmail.conf

Uncomment the VirtualHost block. Change the IP address to *:80 and replace webmail.example.com with your own domain name. Don’t forget to create an A record in DNS.

<VirtualHost *:80>
  DocumentRoot /usr/share/squirrelmail
  ServerName webmail.example.com
 </VirtualHost>

Save and close the file. Then enable this virtual host:

sudo a2ensite squirrelmail.conf

The above command will create a symbolic link in /etc/apache2/sites-enabled/ directory pointing to the new virtual host file. Now reload Apache web server.

sudo systemctl reload apache2

Enter your webmail domain name in browser, you should see SquirrelMail login page.

squirrelmail login page ubuntu 16.04

If you want to add HTTPS to webmail, then you can obtain a free TLS/SSL certificate from Let’s Encrypt CA. First Let’s install the certbot client. The client is still named letsnecrypt in Ubuntu repository. The following command will install the client and apache plugin.

sudo apt install letsencrypt python-letsencrypt-apache

Now issue the following command to obtain a free TLS/SSL certificate. Replace the red-colored text with your actual email address and domain name.

sudo letsencrypt --apache --agree-tos --email your-email-address -d webmail.example.com

You will be asked to choose easy or secure. It’s recommended to choose secure so that all http requests will be redirected to https.

let's encrypt apache

Once you hit the OK button, a free TLS/SSL certificate is obtained and installed on the Apache virtual host.

Nginx

If you are using Nginx web server , then create a virtual host file in /etc/nginx/conf.d/ directory.

sudo nano /etc/nginx/conf.d/squirrelmail.conf

Put the following text in the file. Replace webmail.example.com with your own domain name and don’t forget to add an A record in DNS.

server {
  listen 80;
  server_name webmail.example.com;

  root /usr/share/squirrelmail/;
  index index.php index.html index.htm;

  location ~ ^/(.+\.php)$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
  }
}

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx configurations.

sudo systemctl reload nginx

Now you should see SquirrelMail login page in browser.

squirrelmail login page ubuntu 16.04

Let’s obtain a free TLS certificate from Let’s encrypt. Install Let’s Encrypt (certbot) client with:

sudo apt install letsencrypt

Then use the webroot plugin to obtain the certificate. Replace red text with your actual email address and domain name.

sudo letsencrypt certonly --webroot --email your-email-address -d webmail.example.com -w /usr/share/squirrelmail/

You will see the following text indicating that you have successfully obtained a TLS certificate. Your certificate and chain have been saved at /etc/letsencrypt/live/webmail.example.com/ directory.

squirrelmail let's encrypt

After the certificate is obtained, we need to manually configure TLS/SSL settings. Edit the virtual host file.

sudo nano /etc/nginx/conf.d/squirrelmail.conf

Change the configuration to the following.

server {
    listen 80;
    server_name webmail.example.com;
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl http2;
    server_name webmail.example.com;

    root /usr/share/squirrelmail/;
    index index.php index.html index.htm;

    ssl_certificate /etc/letsencrypt/live/webmail.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/webmail.example.com/privkey.pem;

    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_protocols TLSv1.1 TLSv1.2;

   ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK';
   ssl_prefer_server_ciphers on;


   location ~ ^/(.+\.php)$ {
      try_files $uri =404;
      fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param HTTPS on;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi_params;
   }
}

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx configurations.

sudo systemctl reload nginx

Step 3: Configure SquirrelMail

Issue the following command on Ubuntu 16.04:

sudo squirrelmail-configure

SquirreMail configure menu will appear.

sudo squirrelmail-configure

There are 10 items in the main menu. The 2nd item: Server Settings must be changed in order to make SquirrelMail work. Other items are optional.

Type 2 and press Enter to configure server settings.

squirrelmail server settings

Select 1, A and B to update the domain nameIMAP server settings, SMTP server settings respectively.

Once that’s done, press S to save configurations and Q to quit. Now visit the Squirrel login page in your browser and login with your email address and password.

squirrelmail ubuntu 16.04

SquirrelMail web interface

squirrelmail nginx

That’s it!

I hope this tutorial helped you install SquirrelMail on Ubuntu 16.04 with LAMP or LEMP. As always, if you found this post useful, then subscribe to our free newsletter.You can also follow us on Google+Twitter or like our Facebook page.

Rate this tutorial
[Total: 1 Average: 5]