an open source technology and e-commerce related site

Unmanaged VPS hosting and iRedmail

Written by Matthew Cooper on January 01, 2013

A while ago a client of mine began experiencing growing pains in the hands of a budget hosting company called Neubox. With no warning Neubox would often perform server maintenance or migrate the site to other servers. This would put everything offline for hours at a time while also leaving my client without email communication. The last straw was when a large ad campaign was running and the server went down for maintenance causing money to be lost in advertising and potential sales.

Unmanaged VPS hosting

At their wit's end, my client instructed me to find a semi dedicated hosting solution for under $50 USD a month. After some quick research I found myself deciding between VPS packets offered by and I decided to give a go since they offered more in terms of hardware for -/+ $40 USD a month:

  • CPU: 2 x 2.26 Ghz
  • RAM: 2048 MB
  • Disk Space: 100 GB
  • Bandwidth: 3000 GB/monthly

Since I consider myself pretty competent on the command line I thought why not save a few extra bucks and go for the unmanaged solution? Cutting out the middleman and doing things yourself can be intimidating at first, but once you get your hands around the bash a world of possibilities opens up. Want Nginx instead of Apache? Easy. Want the latest development release of PHP? No biggie.

Since my client refused to spend $5 USD a month on each employee to have google apps (he has around 120 employees), I had to install a simple mail server. The out of the box operating system provided by tmzvps is CentOs 6.3 (64 bits) which is actually perfect for the kind of mail server setup I needed. Yet I knew that from past experiences that configuring Dovecot and Postfix properly is not so straightforward. I needed to find a simpler solution without having to fall back on using webmin (which to me defeats the point in having bash control to begin with).

Introducing iRedmail

iRedmail is an open source mailing solution which automatically configures Dovecot and Postfix, MySQL and Roundcube as a web interface. They also include a very powerful email server administration panel called iRedadmin. The problem I found is that iRedadmin is written in python and is programmed to work out of the box using the mod_uwsgi Apache module. This was a small blocker since I had already had Nginx setup with PHP 5.4 (fpm).

How to get iRedadmin running on Nginx – Quick and dirty

Firstly, WSGI is well known protocol so I knew there must be some standalone server implementation for Nginx. There is, and you can read more here. Although not a permanent solution, I was able to get it running on Nginx using the following steps:

  1. Grab a copy of the source of uWSGI for Python and compile it:
    1. wget
    2. tar xzf uwsgi-latest.tar.gz
    3. cd uwsgi-X.X.X
    4. python build
    5. make
    6. cd ..
    7. mv uwsgi-X.X.X /opt/uwsgi
  2. Install virtualenv for Python and create a standalone python home directory in the document root of iredadmin.
    1. yum install python-virtualenv
    2. virtualenv /var/www/vhosts/iredadmin/python-home
  3. Now, uWSGI is a stand alone server so what we want to achieve here is for uWSGI to communicate with Nginx. To do that we modify the Nginx Virtual Block (the term for Nginx “virtual hosts”) settings to point to the document root of iredadmin and configure it to listen to uWSGI on a predefined port (I’ll use 8889 in this example) on localhost.
    1. server {
    2. listen 80 default_server;
    3. server_name;
    4. location / {
    5. include /opt/uwsgi/nginx/uwsgi_params;
    6. uwsgi_pass;
    7. uwsgi_param UWSGI_PYHOME /var/www/vhosts/iredadmin/python-home;
    8. uwsgi_param UWSGI_CHDIR /var/www/vhosts/iredadmin;
    9. uwsgi_param UWSGI_SCRIPT iredadmin;
    10. }
    11. location /static {
    12. alias /var/www/vhosts/iredadmin/static/;
    13. }
    14. }
  4. The next thing we need to do is to launch uWSGI (remember this is just a quick and dirty solution).
    1. /opt/uwsgi/uwsgi --socket &
  5. Finally, restart Nginx:
    1. /etc/init.d/nginx restart

You should now be able to open up iredadmin in your browser using Nginx.

Final thoughts

Choosing an unmanaged VPS was a learning experience – I reinstalled everything from zero on numerous occasions to get things how I wanted. In the end though, I saved some money in hosting expenses and also had a completely customized web and email server stack for under $40 USD a month not to mention a much happier client.

I hope you found this article interesting; if you did I would love to hear from you.
Follow me on Twitter @debugthat. Thanks!

Free Web Hosting