Category Archives: Set up a new Mac Server

Deploying Project Bordeaux onto a VM image

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:

$echo ‘>>Upgrading apt-get’
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 apt-get install postfix
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

sudo /etc/init.d/postfix start

Next, install the SSL libraries

sudo apt-get install libsasl2 sasl2-bin# edit the file /etc/default/saslauthd file
—————————————————————————————
# 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

dpkg-statoverride –force –update –add root sasl 755 /var/spool/postfix/var/run/saslauthd
sudo /etc/init.d/saslauthd start
telnet mail.example.com 25

Install DoveCot

sudo apt-get install dovecot-common dovecot-imapd dovecot-pop3d
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.

config.action_mailer.raise_delivery_errors=true
# 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.

export PATH=/var/lib/gems/1.8/bin:$PATH

Ports:
IMAP – 143
IMAPS – 993
POP3 – 110
POP3S – 995

Migration problems with Apache from Leopard to Snow Leopard

I migrated my machine from Leopard to Snow Leopard, a few days ago. Then, I applied the Apple’s latest security patch. Unfortunately, it broke the Apache WebServer. I had to dig into the Console log to fix the error. Apparently, there is an issue with the ‘/usr/libexec/apache2/mod_include.so‘ file.

Therefore, I commented out the inclusion of mod_include from ‘/private/etc/apache2/httpd.conf’ file.

#LoadModule include_module libexec/apache2/mod_include.so

Also, I had to install the lynx (text-based browser for apachectl)

$ sudo port install lynx

And, several packages needs to be upgraded, for patching for 32-bit architecture to 64-bit architecture of Snow Leopard

$ sudo port upgrade –enforce-variants ncursesw ncurses openssl readline

sudo port upgrade ruby

$ sudo env ARCHFLAGS=”-arch x86_64″ gem install –no-rdoc –no-ri mysql —   –with-mysql-dir=/usr/local/mysql –with-mysql-lib=/

Note: the architecture of the CPU is now purely 64-bit. Thus, MYSQL gem needs to be compiled as x86_64

Also, mongrel and mongrel_cluster needs to be installed as well. They don’t get copied over from Leopard to Snow Leopard migration. In the /Library/Ruby/Gems/1.8/gems will be those packages. And, in the /usr/bin will be the gem scripts, e.g. mongrel_rails and mongrel_cluster_ctl

$ sudo gem install mongrel mongrel_cluster

Additionally, it is necessary to modify the .profile file, as MacPort puts /opt/local/bin before /usr/bin in the path. This causes problem.

The problem is with mongrel_rails loading the necessary ruby libraries. Thus, I modified .profile to:

export PATH=/usr/bin:/usr:sbin:/opt/local/bin:/opt/local/sbin:$PATH

This allows /usr/bin/mongrel_rails to take precedence over /opt/local/bin/mongrel_rails and fixes $LOAD_PATH problem with ruby loading incorrect libraries.

The correct libraries should be coming from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/ruby/gems/1.8/gems and not /opt/local/lib/ruby/gems/1.8/gems

Setting up my Mac Mini Server

Last night and today, I have been busy setting up my Mac Mini Server. Here’s what I have done so far.

  1. Install XCode (without ‘cc‘ language package, Mac Port will not install).
  2. Install Mac Ports
  3. Using Mac Ports and install the following packages: (sudo port install …)
    • ruby, ruby-gems (not needed, ruby 1.8.7 and gem 1.3.4 already installed by the Snow Leopard by default)
    • Perl (not needed, already installed by the Snow Leopard by default)
    • rails 2.2.2 (not needed, already installed by the Snow Leopard by default)
    • pound
    • wget
  4. Install following Gems (sudo gem install …..), many gems are already installed by Snow Leopard by default. They are at located: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/, But, using sudo gem install xxx without additional installation of Ruby with MacPort, Mac will now put gems into /Library/Ruby/Gems/1.8/
    • RedCloth (not needed, already installed by the Snow Leopard by default)
    • BlueCloth
    • mongrel (not needed, already installed by the Snow Leopard by default)
    • mongrel_cluster
    • ruby-aaws
    • json
    • imdb
    • net-sftp (not needed, already installed by the Snow Leopard by default)
    • capistrano (not needed, already installed by the Snow Leopard by default)
    • httparty
    • MYSQL 2.8.1 adapter gem (note, that Snow Leopard is now pure 64-bits, and earlier 2.7 does not work. Therefore, x86_64 architecture is needed”. Furthermore, there is a bug with 2.8.1, rdoc and ri do not work.)
  5. sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql --   --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib   --with-mysql-include=/usr/local/mysql/include
  6. Netbeans-ide 6.8 (NetBeans-6.7.1 was designed to work with Ruby 1.8.6, and therefore does not work with Snow Leopard correctly.)
  7. install Aquamac text editor

emacsclient -a /Applications/Aquamacs\ Emacs.app/Contents/MacOS/Aquamacs\ Emacs “$@”

  1. MYSQL (x86 and not PowerPC package)- It is important to read the instruction provided by Sun, because the default MYSQL installation that comes with Mac OSX does not offer a way for uninstallation. It must be manually aliased and the path in the .profile must be reconfigured. Setup MYSQL database & change root password (see http://www.cyberciti.biz/faq/mysql-change-root-password/)
  2. $ mysqladmin -u root password NEWPASSWORD
  3. Additionally, the /private/etc/php.ini file needs to modified to take MYSQL default values (see http://support.apple.com/kb/HT3077?viewlocale=en_US)
pdo_mysql.default_socket=
mysql.default_socket=
mysql.default_host=
mysql.default_port=
mysql.default_user=
mysql.default_password=
  1. PHPMyAdmin (requires enable the Apache server’s HTTPD.CONF file to accept PHP extension)
    uncomment the following file from httpd.conf file
  2. $ LoadModule php5_module        libexec/apache2/libphp5.so   # uncomment it in the httpd.conf file
  3. Move over the data from my existing server.