Rails and Leopard: A smooth upgrade

Posted on October 28, 2007

At 26th October, my leopard order arrived, I wrote about it on my other blog. I was testing it for my G5 machine, and it failed to install when I do upgrade of OS from Tiger to Leopard. Finally I found out, its not because of the bug inside the system, but it because of system conflict from some applications installed, so far I gather from some forums, these are the applications affected: ShapeShifter and Application Enhancer, both product from Unsanity. See this forum for more details. Just be prepared to uninstall all the application which you think can affect the default skin of Mac OS X. After that, get ready to back up all your file for pre-caution, so far from my experience, you do not need to do any backup if you do the upgrading of OS from Tiger to Leopard.

I have been thinking twice when I want to upgrade to leopard. Because Apple shipped Leopard with pre installed 29 gems, Ruby 1.8.6 and It run on ZFS or so called 64bits, rather than Tiger 32bits. The implication that may happen, if I do the upgrade, my current configuration and installation which installed with "make install" showed here, I afraid will be broken or overwrite by the default configuration after upgrading Leopard. Next is the Image Magick installation issue which I think will probably have some problems, memory leaked, and incompatibility issue , reason is the 64bits OS. Beside, I have a lot applications installed on my Tiger, and I have projects need to be done, I can't afford spending my time to clean install my Mac to Leopard and re-install all my applications, too much time taken. After a smooth upgrade I done for my fellow friend Hong Kiat, then only I tried out on my mac book.

After the upgrade, there are 2 installations of Ruby on Rails development kits, the first installation is from the carried over from Tiger, and the second one is from Leopard default. So there are 2 locations of Ruby on Rails Installation which is "/usr/local" because all my installation earlier is prefix to that location, and default leopard location can be found on "/usr/bin".

rubify:~ chardy$ which ruby
/usr/local/bin/ruby

rubify:~ chardy$ ruby -v
ruby 1.8.5 (2007-03-13 patchlevel 35) [i686-darwin8.9.1]

rubify:~ chardy$ rails -v
Rails 1.2.5

rubify:~ chardy$ /usr/bin/ruby -v
ruby 1.8.6 (2007-06-07 patchlevel 36) [universal-darwin9.0]

rubify:~ chardy$ /usr/bin/rails -v
Rails 1.2.3

And after the upgrade I found out, all my worry earlier can be easily solved, and I forgotten UNIX system can be set the environment, so I just point all my earlier Tiger environment to Leopard. Just copy modified ~/.profile file like below to point all my installation to /usr/local/bin. I still using ruby 1.8.5 for current development.


PATH="/bin:/sbin:/usr/bin:/usr/sbin"

export PATH="$PATH:$HOME/bin"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH="/usr/local/man:$MANPATH"
export PATH="$PATH:/usr/local/mysql/bin"

I have encountered this problem when load the terminal.


perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
     LC_ALL = "En_US",
     LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Then I inputed below to my ~/profile again:


# This setting is for the new UTF-8 terminal support
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

And since I still use macport, I also added export PATH=/opt/local/bin:/opt/local/sbin:$PATH to ~/.profile

So, you can do upgrade to new Leopard operating system without a lot of worry. Just insert the DVD and upgrade. All other installation is taken care. Just restore your existing profile setting. Then roll it out :-) FYI, Leopard comes with both Apache 2.2 and 1.3, default on the Sharing control panel is boot up Apache 2.2. Have fun!

Watch out Hivelogic for his new articles about installation rails on leopard.

Back From Rails Conf 2007

Posted on May 27, 2007

Back to Singapore again at 25th May 2007. Having jet lag, and get myself a good rest after that. The trip was awesome, this is my first time to travel so far. Really truly aspiring that Railsconf 2007 attendee reach 1600 people, prove that Rails Community grow rate is high. Chad Fowler bring the message about community, a call to community which every one working together, support and bring up the Rails community.

Chad introduced David to talk about Rails 2.0. According to DHH, "Rails 2.0 is not a beautiful unicorn, won't solve all your problems, and it is real. I think to myself, okay need to shoot for The Rails Way being about 2.0, perhaps even the first Rails 2.0 book? The timing might be perfect."

David's 9 things I love about Rails 2:

  1. Breakpoints are back AND drop-in debugging is now supported! The debugging console pops up right in the Mongrel process. Looks really good and powerful. David says, "Kent Sibilev deserves a world of thanks for getting this to work.
  2. HTTP performance improvements. The _include_tags now have a :cache=>true option that combines JS and CSS files together and gzips them to drastically improve performance.
  3. ActiveRecord QueryCache. Caches queries that have already been executed for performance boost.
  4. Renderers and mime types not conflated in the naming of the view templates anymore. (Refers to the new .erb and .builder extensions), Javascript and CSS packaging and zipping.
  5. Better config and initializer directory structure cleans up the mess of environment.rb
  6. Sexy migrations! Big improvement in the syntax of migration files and an example of a 3rd party plugin making it into core very quickly.
  7. Much better HTTP authentication support baked in.
  8. MIT license assumed now. Plugin generator script adds the MIT license by default.
  9. Spring cleaning. Improvements to basic Rails code and lots of 1.2 deprecations being moved out completely now.
    ____        _ __        _         __                  
   / __ \____ _(_) /____   (_)____   / /   ____ _   _____ 
  / /_/ / __ `/ / / ___/  / / ___/  / /   / __ \ | / / _ \
 / _, _/ /_/ / / (__  )  / (__  )  / /___/ /_/ / |/ /  __/
/_/ |_|\__,_/_/_/____/  /_/____/  /_____/\____/|___/\___/ 
                                                          

Meanwhile, I plan to blog about my thought about the RailsConf 2007 session content which I attending.

Full Ruby on Rails Installation on Mac Intel

Posted on January 02, 2007

Installing Ruby on Rails development platform, its a long process, which we need to do with our terminal, from download the source files itself to the installation part. Make it simple. Here, I just provided the installation script for Mac Intel platform since i am using it ;p and it proven. Just run a shell script file and run the whole installation. Download the file below:

Download Mac Intel Script Here

The Installation including:

  • Ruby 1.8.4
  • Rails Edge
  • Gems
  • FastCGI
  • Lighttpd
  • Image Magick (also as RMagick gem)

Those are the basic installation of so-called rails ready platform. For some cases you need to install your own gem by yourself.

After download rails-intel.tar.gz, just run the command:

$ tar zxf rails-intel.tar.gz

Then open up the script file to get better understanding how it work and all the installation pointing to /usr/local (you can change it, just change the PREFIX), Next, its better to set the path correctly for your sheel environment, normally the file to set will be .profile or .bash_login under your home folder:

export PATH="$PATH:$HOME/bin"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH="/usr/local/man:$MANPATH"

Before you run the script, just better create a directory 'src' inside your home folder and run the script from '~/src/' as the starting point. Next, run the script:

$ sudo ./rails-intel.sh

Wait for the installation finishing, the last piece of installation process running is mysql installation. After mysql installation done, viola.. run the script below for mysql gem

# TODO Do this after MySQL is installed
# NOTE: You may have to do "sudo gcc_select 3.3" first.
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

Done!

Lighty for Rails

Posted on January 02, 2007

Today i will discuss about Lighttpd installation. I am making few assumptions:

  • Your machine running on Linux or Unix platform, infact, there is no distribution of lighty in Windows platform.
  • Localhost as your IP and no other services running on port 80.
  • No RPM please. This guide support for all UNIX/Linux platform.
  • Ruby installed and Rails installed.

Below are the step by step installation:

Run your terminal, through ssh or desktop also applicable ;p Firstly, get the distribution first.

cd /usr/local/src
wget http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz
tar zxvf lighttpd-1.4.8.tar.gz
cd lighttpd-1.4.8

Make sure you put all your installation in "/usr/local/src", no doubt, just for tidy file management purposes. If you running on Mac OS X, there is no "wget" command, use below:

curl -O http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz
tar zxvf lighttpd-1.4.8.tar.gz
cd lighttpd-1.4.8

Next, start to configure:

./configure
make 
sudo make install

Assume lighttpd already successful installed here.

Start configure the config file for running rails application and php. Below just the location where i put my setting file.

  • Lighty's config file at /etc/lighttpd/lighttpd.conf
  • Lighty's runtime pid file at /var/run/lighttpd.pid
  • Lighty's access logs written to /var/log/lighttpd/access_log
  • Lighty's error logs written to /var/log/lighttpd/error_log
  • Rails application will be deployed to home_dir/rails_application_folder
  • PHP aplication will be deployed to home_dir/public_html

In Linux, home_dir = /home and Mac OS X, home_dir = /Users

We will use virtual host for every application deployed. Before, i have created user chardy with configuration as apache group (just let it be under apache group, there is a purpose on that)

su -
useradd -g apache -G apache chardy
passwd chardy
su - chardy
mkdir public_html
rails depot

We need to install PHP first in order to run PHP application. Just follow the steps:

su -
cd /usr/local/src/
wget http://sg2.php.net/get/php-5.1.1.tar.gz/from/sg.php.net/mirror
tar zxvf php-5.1.1.tar.gz
cd php-5.1.1
./configure --enable-fastcgi \
 --enable-force-cgi-redirect
make
make install

Tips: for most common support php module, do below configuration.

./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share 
--includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var 
--sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --with-libdir=lib 
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-force-cgi-redirect --disable-debug 
--enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-db4=/usr --with-exec-dir=/usr/bin 
--with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-gettext --with-gmp --with-iconv 
--with-jpeg-dir=/usr --with-openssl --with-png --with-expat-dir=/usr --with-pcre-regex --with-zlib 
--with-layout=GNU --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes --disable-safe-mode 
--enable-sockets --enable-sysvsem --enable-sysvshm --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx 
--with-pear=/usr/share/pear --with-kerberos --enable-ucd-snmp-hack --enable-memory-limit --enable-shmop 
--enable-calendar --enable-dbx --enable-dio --enable-soap --with-mime-magic=/etc/httpd/conf/magic --without-sqlite 
--with-libxml-dir=/usr --with-xml --with-mysql --with-gd --with-dom --with-dom-exslt --enable-fastcgi 
--enable-force-cgi-redirect

To test PHP5 whether is running correctly:

php -v
PHP 5.1.1 (cgi-fcgi) (built: Jan  3 2006 23:48:02)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2005 Zend Technologies

It will show up PHP 5.1.1 (cgi-fcgi). Next, configure your lighttpd.conf

su -
mkdir /etc/lighttpd/
cd /usr/local/src/lighttpd-1.4.8
cp doc/lighttpd.conf /etc/lighttpd/
vi /etc/lighttpd/lighttpd.conf

Edit the lighttpd.conf to satisfy few lines below first:

server.modules = ("mod_rewrite", "mod_accesslog", "mod_fastcgi")
server.port = 80
server.bind = "localhost"
# server.username = "apache" 
# server.groupname = "apache"
# server username and groupname is not necessary, if not set, all will ignored
server.pid-file = "/var/run/lighttpd.pid"
accesslog.filename = "/var/log/lighttpd/access_log"
server.errorlog = "/var/log/lighttpd/error_log"
server.indexfiles = ( "index.html" )
url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )
server.document-root = "/Library/Rails/" + var.appname + "/current/public"
server.error-handler-404 = "/dispatch.fcgi"

Below is the sample configuration to be added for rails configuration:

#### depot.spiragram.com ####

$HTTP["host"] =~ "depot.spiragram.com" {

  server.document-root     = "/home/chardy/depot/public/"
  server.errorlog          = "/home/chardy/log/lighttpd_error.log"
  accesslog.filename       = "/home/chardy/log/lighttpd_access.log"

  server.error-handler-404 = "/dispatch.fcgi"
  server.error-handler-500 = "/500.html"

  fastcgi.server           = ( ".fcgi" =>
                               ("depot.spiragram.com" =>
                                 ( "socket"            => "/tmp/lighttpd-fcgi.socket",
                                   "bin-path"          => "/home/chardy/depot/public/dispatch.fcgi",
                                   "bin-environment"   => ("RAILS_ENV" => "production"),
                                   "min-procs"         => 1,
                                   "max-procs"         => 5,
                                   "idle-timeout"      => 120				
                                 )
                               )
                             )

}

## end subdomain entries

For PHP configuration below:

$HTTP["host"] =~ "phpsite.spiragram.com" {

  server.document-root  = "/home/chardy/public_html/"
  server.errorlog       = "/home/chardy/log/lighttpd_error.log"
  accesslog.filename    = "/home/chardy/log/lighttpd_access.log"
  server.indexfiles     = ( "index.php", "index.html" )

  fastcgi.server        = (".php" => (("bin-path" => "/usr/bin/php",
               "socket" => "/tmp/phpsite.socket",
               "max-procs" => 1,
               "bin-environment" => ("PHP_FCGI_CHILDREN" => "1",
                                     "PHP_FCGI_MAX_REQUESTS" => "5000"
                                     ),
               "bin-copy-environment" => ("PATH", "SHELL", "USER" ),
               "broken-scriptfilename" => "enable"
              ))
  )
}

Run lighttpd server by typing

lighttpd -f /etc/lighttpd/lighttpd.conf

To stop lighttpd server

killall lighttpd

lazy way ;p

To check your installation is running or not, just point it to below url (example):

http://depot.spiragram.com - rails application

http://phpsite.spiragram.com/index.php - php application. To test php application, just create th index.php

su - chardy
cd public_html
echo '' > index.php

You can see rails page and php info page after you access site provided according to your configuration of v-host.