Topic: Mac OS X Installing Required Software

Topic type: Topic

Describes the steps necessary for installing Kete's required software on a Mac OS X host.

Originally written by Walter McGinnis, Kete Project Lead for Katipo Communications, Ltd.

Part of the Installation Guide


Note: This section covers both Mac OS X 10.4.11 (Tiger) and Mac OS 10.5.1 (Leopard). Referred to as 10.4 and 10.5 from here forward. Pay careful attention to what steps are marked for each

Compatibility Note: A new set of simplified instructions based on the Homebrew package manager (http://github.com/mxcl/homebrew) for Mac OS X 10.6 Snow Leopard and Mac OS 10.5 Leopard are being trialed. This topic will be updated with those instructions in time for the 1.3 release. In the meantime, for 10.6 simply use the 10.5 instructions. For earlier versions of REE, you may need to configure REE with the "--no-tcmalloc" flag (recommended for 10.5, too).

Install MacPorts

Follow the instruction at http://www.macports.org/install.php to install MacPorts on your system. Make sure you meet all the requirements and test it's working before continuing.

Install Required Software for Running Kete

So lets get installing. Run the followig from the console:

10.4: Tiger needs Ruby and RubyGems installed rom MacPorts, so you'll need to run this next command
10.5: Leopard includes Ruby and RubyGems already, so you can skip to the next command

$ sudo port install ruby rb-rubygems

10.x: Then for both systems, run

$ sudo port install git-core memcached nginx wget zlib unzip gzip libxslt pcre yaz zebra curl readline-5 mysql5 +server

10.4: We can install the Ruby-Mysql adapter via MacPorts

$ sudo port install rb-mysql

10.5: We use the gem version of the Ruby-Mysql adapter

sudo env ARCHFLAGS="-arch i386" gem install mysql --with-mysql-config=/opt/local/bin/mysql_config5

Note: If you use Ruby Enterprise Edition or upgrade to a later version of RubyGems, you may to repeat the above step, but with an additional "--" as shown below:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5

(optional - enables conversion of uploaded HTML, Plain Text, PDF, and Microsoft Word documents to the description of the document)

$ sudo port install poppler poppler-data wv lynx

(optional - enables support for harvesting embedded metadata in uploaded files, see mini_exiftool gem step later)

$ sudo port install libexif p5-image-exiftool

 

Installing the Rails framework

You need an installation of Ruby. Ruby Enterprise Edition is a product from the same people that make mod_rails/Passenger (discussed at the bottom of this page). It's optimized to run faster than a standard installation of Ruby. It requires a few extra installation steps, but it's well worth the effort. (for instructions on using debians packages, see an older version of this topic)

The great thing about Ruby Enterprise Edition (refered to as REE) is that the installer does the installing of Ruby and Rails in one go. It takes less than 15 minutes to setup once downloaded (depending on system speed) and less than 10 minutes to update in the future (depending on the amount of sites you have). Start by following the instructions at http://www.rubyenterpriseedition.com/download.html (download, extract, install). Keep the settings as the default ones REE assigns.

Warning: Versions prior to 20090610 contained a security issue which could cause DoS issues. It is highly recommended that you use 20090610 or a newer version when installing. If you have a previous version of Ruby Enterprise Edition, we recommend upgrading it as soon as possible.

Now add the following to the .bash_profile, and .bashrc filea of any users that'll affect the installation (root, kete, and yourself for example). Be sure to use the correct path for REE; it varies by release. Replace the X's in the string below.

# Use correct Ruby, RubyGem paths
PATH=/opt/ruby-enterprise-1.8.6-2009XXXX/bin:$PATH
export PATH

Then as both root and the kete user, check that we are using the correct RubyGems version:

$ which gem
/opt/ruby-enterprise-1.8.6-2009XXXX/bin/gem # should look something like this with correct date

Note: If you plan to use Ruby Enterprise Edition as well as Capistrano, an extra step is necessary. See how to Configure sudo path in capistrano deployments.

Additional Setup Instructions

MySQL

You'll need to append this to your PATH in ~/.profile file:

/opt/local/lib/mysql5/bin

Now we initialize and configure mysql to start at boot time. We'll also set the mysql root password and set up unicode to be the default charset. Make sure you save your mysql root password, you'll need it later!

$ sudo -u mysql mysql_install_db5
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
$ mysqladmin -u root password 'new-password'

We want Unicode (utf8) to be our mysql default character set, too. Create /opt/local/etc/mysql5/my.cnf via sudo and your favorite text editor and place this in it:

[client]
default-character-set=utf8
[mysqld]
init-connect = SET NAMES utf8
character-set-server = utf8

Restart mysql, connect to the default database, and check that it now has the right settings:

$ sudo launchctl stop org.macports.mysql5
$ sudo launchctl start org.macports.mysql5

If the above doesn't work (it should after next reboot), use this:

$ sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop mysql5
$ sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start mysql5

You can confirm that required (system, server) charset variables now point at utf8 by connecting to the mysql database as mysql root (remember you set that password above) and running:

SHOW VARIABLES LIKE 'character_set%';

Aside from file system and dir, everything else should be utf8.

ImageMagick

Kete uses ImageMagick and Rmagick (the ruby binding for Imagemagick) to create thumbnails of images, make captcha images, etc. I'm not super happy with Rmagick's performance, so we might move to ImageScience in the future, but for you now, we need to install this stuff for images.

Unfortunately installation of Rmagick on Mac OS X isn't as easy it should be because the MacPorts version of ImageMagick isn't configured correctly to find the ghostscript fonts. This is a well known issue and thankfully there are instructions for how to make it work.

To install ImageMagick and Rmagick correctly for 10.4 follow steps 4 through 6 in this guide:

http://rmagick.rubyforge.org/install-osx.html

Or on 10.5 use this installer:

http://norbauer.com/notebooks/code/notes/rmagick-for-rails-on-os-x-leopard

Memcached

We'll turn it on as a daemon that will run at boot (thanks Jesse Byler for the revised plist file). You may want to start it only when you are doing development, since it can eat up RAM. You may just want to manage it directly from the command line via the "memcached" command itself.

$ sudo curl -L http://kete.net.nz/documents/0000/0000/0044/local.server.memcached.plist.txt -o /Library/LaunchDaemons/local.server.memcached.plist

Now it is ready to run:

$ sudo launchctl load -w /Library/LaunchDaemons/local.server.memcached.plist
$ sudo launchctl start local.server.memcached

If you aren't running your development Kete server, you probably want to turn off the Memcached daemon with the following (just remember to turn it on again when you do!):

$ sudo launchctl stop local.server.memcached

HTTP Request Server

We recommend Apache 2 in combination with Ruby Enterprise Edition for optimal performance.If you'd prefer to use Nginx with Mongrel, see an older version of this topic.

Apache 2 was installed earlier so, go ahead and install the passenger gem (the gem was installed during the setup of Ruby Enterprise Edition, if you are using a different interpreter, the run 'gem install passenger' as root, then continue).

root@host: # passenger-install-apache2-module

Copy the Apache2 config lines it gives you at the end of the file to the end of your apache2.conf configuration file at /etc/apache2/apache2.conf. The lines look similar to this (paths may differ depending on which ruby implementation you're using):

LoadModule passenger_module /opt/ruby-enterprise-1.8.6-2009XXXX/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so
PassengerRoot
/opt/ruby-enterprise-1.8.6-2009XXXX/lib/ruby/gems/1.8/gems/passenger-2.2.2
PassengerRuby
/opt/ruby-enterprise-1.8.6-2009XXXX/bin/ruby

Some of Kete's downloading functionality requires an authorization step.  If used a lot this potentially can slow all requests being served from the site.  Thankfully there is an easy solution that Kete knows to use if enabled; X-sendfile.  You need to do the following to set it up:

root@host: # cd /usr/local/src/; curl -L http://tn123.ath.cx/mod_xsendfile/mod_xsendfile-0.9.tar.gz # or get the latest version of the source
root@host: # tar xfz mod_xsendfile-0.9.tar.gz
root@host: # cd mod_xsendfile-0.9
root@host: # apxs -cia mod_xsendfile.c

Then you need to add the following to your Apache2 config file (either global, or in a virtualhost):

XSendFile on
XSendFileAllowAbove on

And force a reload of apache:

root@host: # apachectl force-reload

Open up /etc/apache2/httpd.conf in your favourite editor, and change the following settings:

User    <-   the user running the kete app(s). Usually kete or yourself.
Group  <-   the group of the user running the kete app(s)

In the same file, uncomment the following line:

Include /private/etc/apache2/extra/httpd-vhosts.conf

In /etc/apache2/extra/httpd-vhosts.conf, uncomment the following line:

NameVirtualHost *:80

Run the following commands (otherwise Kete isn't installable because of missing dependancies).

root@host: # ln -s /usr/local/bin/zebrasrv /usr/bin
root@host: # ln -s /usr/local/bin/zebraidx /usr/bin

And finally, to make the apache restart command more consistant for the rest of the guide, type

root@host: # mkdir /etc/init.d
root@host: # ln -s /usr/sbin/apachectl /etc/init.d/apache2

With those changes made (and files saved), restart Apache:

root@host: # /etc/init.d/apache2 restart

and then look for any errors causes by bad configuration by running:

root@host: # tail -n 200 /var/log/apache2/error_log

Important Note: At this point, Apache2 and Passenger are installed but not yet configured for our Kete site. We'll handle that in a separate step once we have Kete installed. Until then, web requests will throw an error until you have actually deployed your Kete application.



Next step:
Setting Up the Environment

Discuss This Topic

There are 9 comments in this discussion.

Read and join this discussion

join this discussion