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.

sudo apt install software-properties-common

sudo add-apt-repository ppa:certbot/certbot

sudo apt update

sudo apt install certbot python3-certbot-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 certbot --apache --agree-tos --redirect --hsts --email your-email-address -d webmail.example.com

A free TLS/SSL certificate will be obtained and automatically 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 software-properties-common

sudo add-apt-repository ppa:certbot/certbot

sudo apt update

sudo apt install certbot python3-certbot-nginx

Then run the following command to obtain the certificate. Replace red text with your actual email address and domain name.

sudo certbot --nginx --agree-tos --redirect --hsts --email your-email-address -d webmail.example.com

You will see the following text indicating that you have successfully obtained a TLS certificate, and it’s automatically installed in your Nginx virtual host.

squirrelmail let's encrypt

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.

Rate this tutorial
[Total: 6 Average: 4.5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.


The maximum upload file size: 2 MB.
You can upload: image.