Aug 192010

UPDATE: New version for OS X Lion HERE

I choose the simple and I believe clean way to use everything from macports and passenger.

The advantage is that it’s all isolated from the OS X system and using latest cutting edge version of softwares.

I assume you have textmate, because it’s easy to edit files that need sudo access. Textmate will just ask for your password.

Try and download the 30 days trial for easy of this tutorial.

Trust me, you will love Textmate, it’s state of the art editor.

ps: I use “mate” instead of “open -a TextMate” but not everyone might have the mate symlink.


  • Snow Leopard 10.6.4 or greater
  • Xcode 3.2.3, 2.4.1 or greater
  • Admin privileges on your mac.

Software preliminary:

  • Mysql 5.1.49 (macports)
  • Ruby 1.8.7 (macports)
  • Apache 2.2.9 (part of OS X)
  • Rubygems (download)
  • passenger (gem)
  • ImageMagick
  • rmagick

1. Preparing System

If you are upgrading from Leopard to Snow Leopard, I recommend you delet your old installation.

sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \

1.1 Prepare PATH environment:

$ open -a TextMate ~/.bash_profile

Edit your ~/.bash_profile file and add these 2 line.
Check if they are not there already.

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

1.2 Download and Install Xcode

Full Article

1.3 Download Macports and install

Download Page:

Download Direct Link:

You might use this guide for installing Macports:

Full Install Guide:

1.3.1 Update macports

sudo port -v selfupdate

2. Mysql

2.1 Intall Mysql

sudo port -v install mysql5-server mysql5

2.2 Make mysql autoload on startup

sudo port load mysql5-server
sudo -u mysql mysql_install_db5

3. Memcached (Optional)

sudo port -v install memcached libmemcached

3.1 Autoload memcached on startup

sudo port load memcached

4. Ruby, Rubygems, Rails, other gems

4.1 Install Ruby from macports

sudo port -v install ruby
$ ruby -v
ruby 1.8.7 (2010-08-08 patchlevel 302) [x86_64-darwin10]

4.2 download rubygems from

cd /tmp
tar xpf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb

4.3 Install rails, rake, rspec etc.

sudo gem install rake rails thin tzinfo capistrano ruby-debug rspec


4.4 install mysql gem

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

5. ImageMagick, Rmagick and mini_magick (Optional)

lets install ImageMagick with support for JPEG, TIFF, WMF, PDF, and PNG images, and for Postscript and TrueType fonts.

sudo port -v install tiff -macosx imagemagick +q8 +gs +wmf
sudo gem install mini_magick rmagick

Test rmagick

$ irb -rubygems -r RMagick
>> puts Magick::Long_version
This is RMagick 2.13.1 ($Date: 2009/12/20 02:33:33 $) Copyright (C) 2009 by Timothy P. Hunter
Built with ImageMagick 6.6.3-0 2010-08-19 Q8
Built for ruby 1.8.7
Web page:
=> nil

6. Passenger

6.1 Install Passenger gem

sudo gem install passenger

6.2 Check Passenger path

passenger-config --root
 -> /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15

6.3 Build passenger for apache

follow instructions on screen

sudo passenger-install-apache2-module

6.4 Enable Passenger on apache:

open -a TextMate /etc/apache2/extra/httpd-passenger.conf

Put this on that file, change wherever necessary for your directories.

LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/
PassengerRoot /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15
PassengerRuby /opt/local/bin/ruby
PassengerMaxPoolSize 6  # maximum global rails servers
PassengerMaxInstancesPerApp 2  # maximum rails servers per application
RailsFrameworkSpawnerIdleTime 1800
RailsAppSpawnerIdleTime 600
PassengerPoolIdleTime 600
PassengerMaxRequests 1000  # after 1000 requests will restart server, to skip memory leak :)

# Enabling NameBased Virtualhost
NameVirtualHost *:80

# my rails app virtual host 1

    ServerName my-rails-app.local
    DocumentRoot "/Users/fred/rails/my-rails-app/public" # change this to match your folder
    RailsEnv "development"
        # change this to match your folder
        # MultiViews must be turned off
        Options -MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    # logs are optional, change this to match your folder
    CustomLog  "/Users/fred/rails/my-rails-app/log/access_log" combined
    ErrorLog   "/Users/fred/rails/my-rails-app/log/error_log"

# my rails app virtual host 2

    ServerName myapp-xyz.local
    DocumentRoot "/Users/fred/rails/myapp-xyz/public"  # change this to match your folder
    RailsEnv "development"
        # change this to match your folder
        # MultiViews must be turned off
        Options -MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    CustomLog  "/Users/fred/rails/myapp-xyz/log/access_log" combined
    ErrorLog  "/Users/fred/rails/myapp-xyz/log/error_log"

6.5 Enable Virtual host on apache:

open -a TextMate /etc/apache2/httpd.conf

Add this new line at the bottom:

# Include Passenger ModRails config file
Include /private/etc/apache2/extra/httpd-passenger.conf

6.6 Add your .local domain to /etc/hosts/

open -a TextMate /etc/hosts

Add this line to that file and change to the name of your choosen application

You might add as many as you want, each line for each that ServerName on your VirtualHost blocks my-rails-app.local myapp-xyz .local

I have more than 50 .local apps in there.

5 Start Apache

first let’s test apache configuration:

apachectl configtest

if you get “Syntax OK” then you are ready to start it

sudo apachectl start

If you want Apache to autostart when you boot your computer,
then enable Web Sharing from preferences.

7. Final

go to your browser and open the url of your application http://my-rails-app.local

If it works, congratulations.

If didn’t work, let me know here in the comments.



  sudo port -v install libxml2 libxslt
  sudo gem install nokogiri -- --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local


sudo port install sqlite3
sudo gem install sqlite3-ruby

9. Sphinx, thinking-sphinx, sphinxsearchlogic

sudo port install sqlite3
sudo gem install thinking-sphinx sphinxsearchlogic


From the comments, some people might want to enable php and your Sites folder.

To be able to enable php and others you will have to enable another default vhost with localhost as servername.

Edit the file /etc/apache2/httpd.conf to enable vhosts

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

then open /private/etc/apache2/extra/httpd-vhosts.conf file,
delete or comment everything from there and add this block only:

# Use name-based virtual hosting.
NameVirtualHost *:80

# Change /Users/fred/ to your appropriate login name

    ServerName localhost
    DocumentRoot /Users/fred/Sites/
    RewriteEngine On
    DefaultType text/html
        DefaultType text/html
        Options +ExecCGI FollowSymLinks Indexes
        AllowOverride All
        Order allow,deny
        Allow from all

Links and Resources

Full Article

essay on old english literature

 Posted by at 3:36 pm

Encrypted image that grows as needed, for linux backups

 osx  Comments Off on Encrypted image that grows as needed, for linux backups
Jul 242010

This command will create an encrypted image on mac OS X that will grow as you need it.
Since I could not find anywhere on the net, I dig on the hdiutil man page and wrapped the command. Ондатра

The image starts with about 600MB in size, which is not wasted actually.

I use this image to backup my sensitive data such as servers config files, mysql databases and repositories.
I set it to use AES 128bit encryption.
Case-sensitive, because Linux fs are Case-sensitive by default. If you don’t set it Case-sensitive you cannot use for linux backups.

hdiutil create -encryption AES-128 -stdinpass -fs “Case-sensitive HFS+” -type SPARSE -nospotlight -volname Servers Servers

it will create a file named Servers.sparseimage

 Posted by at 3:47 pm
Jul 092010

Now a days there are so many good and cheap OpenVZ VPS providers out there.
Just have a look at this blog and you will see what I mean. []

The way OpenVZ virtual machines offers RAM resource is quite different from XEN.
You get Dedicated Ram (guaranteed ram) and Burstable Ram. kahovka-service

Burstable Ram is good when your server has sporadic load spikes, such as blogs and news sites.
Ideally you should not rely on burstable ram, it depends on the Host System. if the host system starts get low on free ram, you will lose that memory and the kernel will kill your processes to recover the ram.

Best is to keep below 90% of your Dedicated ram.

So, here I have an script that will monitor your memory limits. Also check for errors on your openVZ.
it’s perfect for an hourly cron job. It will print output on warnings and errors only.
Will suppress output if your openVZ container is behaving well. :)

for example, put on /etc/cron.hourly/

 Posted by at 9:37 pm
Jun 252010

You can monitor your servers nicely graphs using iStat for iphone.
these are instructions for

Create and edit /etc/istat.conf to match your server specs.
This config is for my OpenVZ vps.

Start istatd server:

you might add it to /etc/conf.d/local.start to auload on startup

Then download iStat for iphone http://bjango .com/apps/istat/ it’s only $0.99
and add your server to the list.

Here are some screenshots, first is server and second image is my macbook discovered with bonjour.

#gallery-1 {
margin: auto;
#gallery-1 .gallery-item {
float: left;
margin-top: 10px;
text-align: center;
width: 33%;
#gallery-1 img {
border: 2px solid #cfcfcf;
#gallery-1 .gallery-caption {
margin-left: 0;
/* see gallery_shortcode() in wp-includes/media.php */

Jun 142009

I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in

Methods I have seen so far:inFOLIO Research Group

1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you will not get the expected result.

2. Using Rmagick to check if the file is an image. This is so slow and uses so much Ram. You can try to initialize an rmagick object from an image file, then rescue when the file is not an image.

3. Using mini_magick to check if a file. This method is faster than rmagick. Implemen ted same way as rmagick.

A Better method for OSX and Linux,  is to use the command line tool “file” included in most UNIX operating systems.

It is very fast and very accurate.

Some examples of content types:

.doc = Microsoft Word document data

.doc = Microsoft Office Document

.pdf = PDF document, version 1.4

.pdf = PDF document, version 1.3

.psd = Adobe Photoshop Image

.png = PNG image data, 3508 x 4961, 8-bit/color RGBA, non-interlaced

.gif = GIF image data, version 89a, 195 x 109

.jpg = JPEG image data, EXIF standard


I hope this can be useful to someone.

Easy installing Nginx + mod_rails passenger OSX

 nginx, osx  Comments Off on Easy installing Nginx + mod_rails passenger OSX
Jun 142009

Requirements:Балки обвязочные

1. XCODE you can download xcode from

2. OSX 10.4, 10.5 or 10.6


1. Install Passenger

$ sudo gem install passenger

now check where is passenger installed:

in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5

2. Install nginx

If you have nginx from macports, deactivate it in case of conflicts.

You can activate anytime later

$ sudo port deactivate nginx

$ wget

$ wget

$ tar xpf nginx-0.7.62.tar.gz

$ cd nginx-0.7.62

I Recommend using nginx 0.6 series because I had a lot of “502 Bad Gateway” with 0.7 series.

$ wget

$ tar xpf nginx-0.6.37.tar.gz

$ cd nginx-0.6.37

$ sudo make

$ sudo make install

$ cd /opt/local/conf

$ sudo cp mime.types.default mime.types

$ sudo cp nginx.conf.default nginx.conf

Edit nginx.conf

$ mate nginx.conf


$ sudo vi nginx.conf

Now edit your /etc/hosts and add the hosts for your local project

$ mate /etc/hosts

3. Start nginx

sudo nginx

4. go to your browser and open project1.local


5. Easy start/restart/stop

add this to your ~/.bash_profile file


1. Nginx is not running

– check the logs

– check if it is really not running:

$ ps aux | grep nginx

2. you see the nginx error “502 Bad Gateway”

– may there is a problem with the /var/folders/ permissions on OSX:

to fix it I did this:

$ sudo find /var/folders/xl/ -name “master” -exec chmod 755 {} \;

$ sudo find /var/folders/xl/ -name “-Tmp-” -exec chmod 755 {} \;

everytime I reboot my mac I had to do that… I still dont know how to fix it…

anybody knows?

That is it for now.

Switch to our mobile site