This tutorial will walk through the steps how to install roundcube with nginx, postfix, and dovecot. This is basically like setting up your own private Google Apps, but it’s all free and managed by yourself. I won’t be walking through all the nuances of making sure your server isn’t marked as spam, blacklisted, and all that other jargon because that’s a tutorial in and of itself. You basically should Google how to setup reverse DNS entries and configuring your server for sending email after you’re done with this tutorial.
Let’s start by installing and enabling postfix and Dovecot:
1 2 3 4 5 |
yum install postfix dovecot systemctl start postfix systemctl enable postfix systemctl start dovecot systemctl enable dovecot |
Now we can download Roundcube. Go to http://roundcube.net/download and click their latest “complete” download link. It will take you to sourceforge – from there you can right click the “direct link” and click “Copy link URL” so you can paste this directly into your terminal to download with wget:
1 2 3 4 |
wget http://downloads.sourceforge.net/project/roundcubemail/roundcubemail/1.0.2/roundcubemail-1.0.2.tar.gz tar -zxvf roundcubemail-1.0.2.tar.gz mv roundcubemail-1.0.2 /usr/share/roundcube mkdir /var/log/roundcube |
I chose to setup a webmail.yoursite.com type of subdomain in an nginx config. Here’s the file I placed in /etc/nginx/conf.d/webmail.yoursite.conf – feel free to change this to your liking:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
server { listen 80; server_name webmail.yoursite.com; root /usr/share/roundcube; # Logs access_log /var/log/roundcube/access.log main; error_log /var/log/roundcube/error.log; # Default location settings location / { index index.php; try_files $uri $uri/ /index.php?$args; } # Redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } #error_page 404 /404.html; # Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead) location ~ \.php$ { # Prevent Zero-day exploit try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini fastcgi_pass unix:/var/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # Deny access to .htaccess files, if Apache's document root location ~ /\.ht { deny all; } # Exclude favicon from the logs to avoid bloating when it's not available location /favicon.ico { log_not_found off; access_log off; } } |
Add the following to the bottom of /etc/nginx/fastcgi_params:
1 2 3 4 5 |
# Roundcube config fastcgi_keep_conn on; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; |
Setup your MySQL database:
1 2 3 4 5 |
mysql -u root -p create database roundcube; create user 'roundcube'@'localhost' identified by 'YOUR PASS HERE'; grant all on roundcube.* to 'roundcube'@'localhost'; quit; |
Test and reload nginx:
1 2 |
nginx -t nginx -s reload |
Edit /etc/php.ini and set your date.timezone setting (I’m using America/New_York):
1 |
date.timezone = America/New_York |
Edit /etc/dovecot/dovecot.conf
Uncomment line 24:
1 |
protocols = imap pop3 lmtp |
Uncomment and modify line 30:
1 |
listen = * |
Edit /etc/dovecot/conf.d/10-auth.conf
Uncomment and change line 10:
1 |
disable_plaintext_auth = no |
Modify line 100:
1 |
auth_mechanisms = plain login |
Edit /etc/dovecot/conf.d/10-mail.conf
Uncomment and modify line 30:
1 |
mail_location = maildir:~/Maildir |
Edit /etc/dovecot/conf.d/10-master.conf
Uncomment and modify lines 96-98:
1 2 3 4 5 |
unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } |
Edit /etc/dovecot/conf.d/10-ssl.conf
Uncomment and modify line 8:
1 |
ssl = no |
Restart dovecot:
1 |
systemctl restart dovecot |
Change permissions of logs and temp directories:
1 |
chmod o+w /usr/share/roundcube/logs /usr/share/roundcube/temp |
Now point your hosts file or DNS record for webmail.yoursite.com at your server, and go to http://webmail.yoursite.com/installer in your browser. You should now be able to walk through the installer pretty easily without many questions. The steps above should have resolved the extra things I had to do during the installer process so this should be good to go!
Don’t forget to click the button that initializes the database on page 3 of the installer. If you’re interested in setting up DKIM signatures, then I’d recommend reading Steve Jenkin’s post on this. Thank you Steve for your hard work getting the OpenDKIM package to be available in EPEL!
Please post any questions, comments, or issues in the comments below and I’ll help you troubleshoot your issues 🙂
Thanks. I successfully installed Postfix and roundcube on my CentOS 7 machine following your tutorial. Please advise if I can configure OpenDKIM on this Posftix setup as described in this Exim tutorial: https://www.rosehosting.com/blog/how-to-install-and-configure-dkim-with-opendkim-and-exim-on-a-centos-7-vps
Thanks in advance!
Hey Ricky,
It’s always great to hear that one of my posts was helpful! Yes, you should be able to install and configure OpenDKIM (thanks to Steve Jenkins’ package for CentOS 7). I’d recommend using his post to set it up – I couldn’t have written it better myself.
Hello!
Great tutorial eve the best, the installation and configuration work very well but I have a doubt… how I can create mail accounts to login? Because once finished the installation and if I open the webmail url is requested the username and password but I don’t have any email account yet.
Thanks in advance!
Hey Soldier,
Sorry for the delay – roundcube doesn’t actually manage user accounts so however you setup roundcube to connect (in this tutorial I setup roundcube to connect to dovecot via IMAP so the user would be added however dovecot handles them, which is typically passed through postfix on your local system so adding a user with a mailbox should work fine) you’ll have to add the user to whatever mail server roundcube connects to.
http://wiki2.dovecot.org/SystemUsers
http://wiki2.dovecot.org/BasicConfiguration
Btw, I don’t want to use my mail service with Google Apps, I want to use as just a mail server because I need to use this with my Laravel Project so I don’t know how to configure the smtp mail server and I want to know how to create the email accounts to start using.
Thank you!
Hi. Thanks for the tutorial. I followed every step and when I try to open http://webmail.yoursite.com/installer i get this:
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
Faithfully yours, nginx.
I checked the error.log and it says this:
*11 connect() to unix:/var/run/php-fpm/www.sock failed (2: No such file or directory) while connecting to upstream, client….
There’s no http://www.sock file in that address. what’s is it? Can you plz help me to fix my problem? Thanks
Hey Alex,
It sounds like you never setup nginx to pass fastcgi through the local unix socket. I have a couple tutorials (one for CentOS 7 and one for CentOS 6) that outline how to setup nginx to pass fastcgi through the local unix: socket instead of using port 9000 or whatever:
CentOS 7: http://robido.com/nginx/how-to-install-web-server-centos-7-using-nginx-php-fpm-mariadb-firewalld/
CentOS 6: http://robido.com/nginx/install-nginx-php-fpm-apc-mariadb-phpmyadmin-centos-6/
You need to specifically look for where it has you edit
/etc/php-fpm.d/www.conf
and create thewww.sock
file and restart php-fpm. After that exists and has the correct permissions/ownership then you shouldn’t be seeing these errors. Let me know if you have any additional questions.Thank you , i followed those steps in that link and now i’m getting this error :
2015/02/04 12:32:48 [error] 4069#0: *1 connect() to unix:/var/run/php-fpm/www.sock failed (111: Connection refused) while connecting to upstream
I changed ‘user’ and ‘group’ to ‘nginx’ in /etc/php-fpm.d/www.conf and it solved my problem.
but i dont know how to create user and password to login in roundcube?
Hey Alex,
You need to add users through your local system typically through useradd. They need a mailbox dir (it should correspond to what your dovecot settings indicate). You should be able to get some additional info with the links below. Let me know if you have any other questions.
http://wiki2.dovecot.org/SystemUsers
http://wiki2.dovecot.org/BasicConfiguration
Hi Jeff 🙂
I have followed your tutorial and got the similar problem as Alex – when I navigate to my site I got message>
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
Faithfully yours, nginx.
But I don’t have anything in my nginx error log.
The problem begins when I add subdomain to sites-enabled.
(you placed it in /etc/nginx/conf.d/webmail.yoursite.conf – but I read that I have it also at sites-available and create symbolic link to sites-enabled)
So, I don’t understand where the problem is. In my /var/www/ I have directory which contains my website, and in nginx conf its root is /var/www/site-name
Roundcube is also in /var/www/roundcube (sybmolic link actually to /usr/share/roundcube) so, I sat root for subdomain conf webmail.mysite.conf like this, but when I add it to sites-enabled I can’t see neither my site nor roundcube.
Can you help me please, I have been stuck there for a long time 🙁
Hi nekoizmase,
It sounds like the problem you’re having is actually with your virtual host configs in nginx. Judging by your directory structure it sounds like you’re on an Ubuntu or Debian based system. It would be tough to tell you exactly how to solve your issue without seeing it myself, but I find that it’s always helpful to setup your virtual hosts to have a custom log file for error and access logs.
You should be able to check the global logs as well which are typically found in
/var/log/nginx/error.log
– check to see if that has some errors about a path not found, or just dotail -f /var/log/nginx/access.log
and refresh the page in your browser to see if it’s even hitting your server.If none of this sheds any light on your problem, then I’m always available on IRC (freenode.net) in the channel #robido during work hours (from 9-6 EST M-F). Stop by and feel free to say “jphase” in the channel and it will notify my IRC client. I’ll see if I can’t help you troubleshoot the issue live.
Hopefully this helps. Cheers.