Moving Project Bordeaux from my Mac dev environment to a Ubuntu Server environment has many challenges. I was up to 2 A.M. last night trying to fix different things. Among different issues, Email and Gems are top two areas.
After I installed the barebone Ubuntu Server 9.1. I needed to ran a bunch of scripts to get it into working order (e.g. X-Server, set up Rails, install Ruby, MySQL, etc.) Anyway the scripts is as follows:
apt-get update;
apt-get dist-upgrade;echo ‘>>Installing vsftd & curl’
sudo apt-get install vsftpd;
sudo apt-get install curl;
sudo vi /etc/vsftpd.conf;
sudo /etc/init.d/vsftpd restart;echo ‘>>Installing mysql’
sudo apt-get install mysql-server php5-mysqlecho ‘>>Installing ruby + rails + gems’
sudo apt-get install ruby-full build-essential;
sudo apt-get install libyaml-ruby libzlib-ruby;
sudo apt-get install rubygem;
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev;
sudo gem install rails -v=2.2.2;
sudo gem install rails -v=2.3.5;
sudo gem install mongrel json net-ssh acts_as_ferret will_paginate spreadsheet ruby-ole chronic packet acts_as_state_machine SystemTimer;
sudo gem install capistrano httparty;
echo ‘>>Installing xserver & windows’
sudo apt-get install xserver-xorg;;
sudo apt-get install libtiff-tools;
sudo apt-get install alien;
sudo apt-get install devscripts;
sudo apt-get install xorg gdm gnome-core;
sudo apt-get install gnome;
sudo apt-get install gnome-desktop-environment;
sudo apt-get install ubuntu-desktop;
sudo dpkg-reconfigure xserver-xorg;
echo ‘>>Installing misc packages’
sudo apt-get install pound;
sudo apt-get install flashplugin-nonfree;
sudo apt-get install openssh-server;
echo ‘>>Installing java’
sudo apt-get install sun-java6-jdk sun-java6-fonts sun-java6-plugin
echo ‘>>Installing git + subversion’
sudo apt-get install subversion git-core git-svn
However, that is not enough. I also needed to install the Mail-Server. This is the really tricky part. Because, according Ubuntu documentation, there are 2 pieces to the puzzle, Postfix (MTA – which is a glorified name for the out-going mail service) and Dovecot (MDA – Incoming mail receiver).
https://help.ubuntu.com/6.06/ubuntu/serverguide/C/email-services.html
https://help.ubuntu.com/community/Postfix
There are lots of steps to get the Postfix working with the SSL. And, all those steps must be followed. Otherwise, it does not work. The steps are:
sudo dpkg-reconfigure postfixpostconf -e ‘smtpd_sasl_local_domain =’
postconf -e ‘smtpd_sasl_auth_enable = yes’
postconf -e ‘smtpd_sasl_security_options = noanonymous’
postconf -e ‘broken_sasl_auth_clients = yes’
postconf -e ‘smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination’
postconf -e ‘inet_interfaces = all’
echo ‘pwcheck_method: saslauthd’ >> /etc/postfix/sasl/smtpd.conf
echo ‘mech_list: plain login’ >> /etc/postfix/sasl/smtpd.confopenssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
mv smtpd.key /etc/ssl/private/
mv smtpd.crt /etc/ssl/certs/
mv cakey.pem /etc/ssl/private/
mv cacert.pem /etc/ssl/certs/postconf -e ‘smtpd_tls_auth_only = no’
postconf -e ‘smtp_use_tls = yes’
postconf -e ‘smtpd_use_tls = yes’
postconf -e ‘smtp_tls_note_starttls_offer = yes’
postconf -e ‘smtpd_tls_key_file = /etc/ssl/private/smtpd.key’
postconf -e ‘smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt’
postconf -e ‘smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem’
postconf -e ‘smtpd_tls_loglevel = 1′
postconf -e ‘smtpd_tls_received_header = yes’
postconf -e ‘smtpd_tls_session_cache_timeout = 3600s’
postconf -e ‘tls_random_source = dev:/dev/urandom’
postconf -e ‘myhostname = mail.example.com’
Next, restart the Postfix server
Next, install the SSL libraries
—————————————————————————————
# This needs to be uncommented before saslauthd will be run
# automatically
START=yesPWDIR=”/var/spool/postfix/var/run/saslauthd”
PARAMS=”-m ${PWDIR}”
PIDFILE=”${PWDIR}/saslauthd.pid”
# You must specify the authentication mechanisms you wish to use.
# This defaults to “pam” for PAM support, but may also include
# “shadow” or “sasldb”, like this:
# MECHANISMS=”pam shadow”
MECHANISMS=”pam”
—————————————————————————————
Make SSL to work with Postfix
sudo /etc/init.d/saslauthd start
telnet mail.example.com 25
Install DoveCot
amend the following line in the file /etc/dovecot/dovecot.conf:protocols = pop3 pop3s imap imaps
It enables the protocols when dovecot is started. Next, add the following line in pop3 section in the file /etc/dovecot/dovecot.conf:
pop3_uidl_format = %08Xu%08Xv
sudo /etc/init.d/dovecot start
can edit the file /etc/dovecot/dovecot.conf and amend following lines:
ssl_cert_file = /etc/ssl/certs/dovecot.pem
ssl_key_file = /etc/ssl/private/dovecot.pem
ssl_disable = no
disable_plaintext_auth = no
And, this is not enough. Additionally, RoR’s ActionMailer works differently on Mac from Ubuntu. Because, Ubuntu does not take :smtp. Ubuntu takes :sendmail; while, Mac takes :stmp and not :smtp.
# Ubuntu does not understand :stmp, it takes only :sendmail. While on Mac, it should be :smtp
config.action_mailer.delivery_method = :sendmail
config.action_mailer.smtp_settings = {
:address => “localhost”,
:port => 587,
:domain => “domain”,
:user_name => “username”,
:password => “password”,
:enable_starttls_auto => true,
:authentication => :plain
}
So, redeploying the app from Mac to Ubuntu, particularly, getting the ROR actionmailer to work is real pain.
Furthermore, Gem tool does not automatically adjust the PATH environment variable.
So, the following must be added to the .bashrc.
Ports:
IMAP – 143
IMAPS – 993
POP3 – 110
POP3S – 995