<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ivan Kuznetsov &#187; ruby</title>
	<atom:link href="http://www.ivankuznetsov.com/tag/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ivankuznetsov.com</link>
	<description>Entrepreneur, Ruby on Rails and Ubuntu fanatic, consultant</description>
	<lastBuildDate>Tue, 18 May 2010 18:39:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Running Rails applications using Nginx with Passenger on Ubuntu Server</title>
		<link>http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html</link>
		<comments>http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html#comments</comments>
		<pubDate>Fri, 14 May 2010 10:40:50 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=279</guid>
		<description><![CDATA[If you&#8217;re planning to run Rails applications on Nginx using Phusion Passenger, and do it on Ubuntu Linux, here&#8217;s what needs to be done. Even though there&#8217;s Ubuntu nginx package available (which works perfectly when you&#8217;re running PHP apps using FCGI), if you want to take into use Phusion Passenger, you&#8217;ll need to recompile Nginx [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ivankuznetsov.com/wp-content/uploads/enterprise_logo.png"><img class="alignleft size-full wp-image-281" title="enterprise_logo" src="http://www.ivankuznetsov.com/wp-content/uploads/enterprise_logo.png" alt="" width="261" height="68" /></a>If you&#8217;re planning to run <a href="http://rubyonrails.org/" target="_blank">Rails</a> applications on <a href="http://www.nginx.org" target="_blank">Nginx</a> using <a href="http://www.modrails.com/" target="_blank">Phusion Passenger</a>, and do it on <a href="http://www.ubuntu.com" target="_blank">Ubuntu</a> Linux, here&#8217;s what needs to be done.</p>
<p>Even though there&#8217;s Ubuntu nginx package available (which works perfectly when you&#8217;re running <a href="http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html">PHP apps using FCGI</a>), if you want to take into use Phusion Passenger, you&#8217;ll need to recompile Nginx from sources.</p>
<p>Instructions below were verified on Ubuntu 10.04 (Lucid Lynx) Server Edition.</p>
<p><span id="more-279"></span></p>
<p>If you already have Nginx ubuntu package installed, uninstall it (NOTE! purge will delete all configuration files &#8211; so if you changed them &#8211; make a backup for future reference):</p>
<pre>sudo aptitude purge nginx</pre>
<p>Assuming you already have Rails stack installed, install Passenger gem:</p>
<pre>sudo gem install passenger</pre>
<p>At the time of this writing the latest version of Passenger is 2.2.11</p>
<p>Let&#8217;s check dependencies that Ubuntu nginx package has and install them before compilation:</p>
<pre>aptitude show nginx | grep Depends</pre>
<div>You&#8217;ll see something like:</div>
<pre>Depends: libc6 (&gt;= 2.4), libpcre3 (&gt;= 7.7), libssl0.9.8 (&gt;= 0.9.8k-1), zlib1g</pre>
<div>Install build dependencies and start nginx module installation (it will offer you to recompile nginx)</div>
<pre>sudo apt-get install libc6 libpcre3 libssl0.9.8 zlib1g
sudo /usr/local/bin/passenger-install-nginx-module</pre>
<div>Choose option 1 (Yes: download, compile and install Nginx for me) unless you need special configuration parameters or need features not enabled by default (like SSL).</div>
<div>Further instructions assume that you also chose default installation directory /opt/nginx.</div>
<div>If you&#8217;ve purchased Passenger Enterprise Edition, don&#8217;t forget to register it:</div>
<pre>sudo /usr/local/bin/passenger-make-enterprisey</pre>
<div>Now add nginx init script (I just copied this from Ubuntu default nginx package):</div>
<pre>sudo vim /etc/init.d/nginx</pre>
<div>with the following content:</div>
<pre>#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/nginx/sbin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

. /lib/lsb/init-functions

test_nginx_config() {
  if nginx -t $DAEMON_OPTS
  then
    return 0
  else
    return $?
  fi
}

case "$1" in
  start)
        echo -n "Starting $DESC: "
        test_nginx_config
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS || true
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON || true
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON || true
        sleep 1
        test_nginx_config
        start-stop-daemon --start --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
        echo "$NAME."
        ;;
  reload)
        echo -n "Reloading $DESC configuration: "
        test_nginx_config
        start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON || true
        echo "$NAME."
        ;;
  configtest)
        echo -n "Testing $DESC configuration: "
        if test_nginx_config
        then
          echo "$NAME."
        else
          exit $?
        fi
        ;;
  status)
        status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx &amp;&amp; exit 0 || exit $?
        ;;
  *)
        echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" &gt;&amp;2
        exit 1
        ;;
esac

exit 0</pre>
<div>Now make this script executable add it to default run levels:</div>
<pre>sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults</pre>
<div>Edit  nginx.conf to look like this:</div>
<pre>user www-data;
worker_processes  4;

error_log  /opt/nginx/logs/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  8192;
    use epoll;
}

http {
    passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11;
    passenger_ruby /usr/local/bin/ruby;

    include       /opt/nginx/conf/mime.types;

    # set a default type for the rare situation that
    # nothing matches from the mimie-type include
    default_type application/octet-stream;

    # This log format is compatible with any tool like awstats
    # that can parse standard apache logs.
    log_format main '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"' ;

    access_log  /opt/nginx/logs/access.log;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  0;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    include /opt/nginx/conf/sites-enabled/*;
}</pre>
<div>Now create virtual hosts structure (so that it looks like the structure created by Ubuntu original nginx package):</div>
<div>
<pre>sudo mkdir /opt/nginx/conf/sites-available
sudo mkdir /opt/nginx/conf/sites-enabled</pre>
</div>
<div>Now it is time to configure your first rails site. Create virtual host configuration in sites-available.</div>
<pre>sudo vim /opt/nginx/conf/sites-available/mysite.com</pre>
<div>Content can be something like:</div>
<pre>server {
        listen   80;
        server_name  www.mysite.com;

        access_log  /home/user/logs/www.mysite.com/access.log;
        root   /home/user/www.mysite.com/public;

        # serve static content directly
        location ~* \.(ico|jpg|gif|png|css|js|swf|html)$ {
          if (-f $request_filename) {
            expires max;
            break;
          }
        }

        passenger_enabled on;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
          deny  all;
        }
}</pre>
<div>Make a symlink in sites-enabled directory and restart nginx.</div>
<pre>sudo ln -s /opt/nginx/conf/sites-available/mysite.com /opt/nginx/conf/sites-enabled/mysite.com
sudo /etc/init.d/nginx restart</pre>
<div>Now open the browser and check that your site is working.</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F05%2Frunning-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html&amp;linkname=Running%20Rails%20applications%20using%20Nginx%20with%20Passenger%20on%20Ubuntu%20Server"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up Ruby, Rails, Git and Redmine on Dreamhost</title>
		<link>http://www.ivankuznetsov.com/2009/07/setting-up-ruby-rails-git-and-redmine-on-dreamhost.html</link>
		<comments>http://www.ivankuznetsov.com/2009/07/setting-up-ruby-rails-git-and-redmine-on-dreamhost.html#comments</comments>
		<pubDate>Thu, 30 Jul 2009 14:58:27 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=195</guid>
		<description><![CDATA[The task is to have: - Redmine installation on redmine.mydomain.com - Several Git repositories on git.mydomain.com with different access rights to each one This proved to be a non-trivial task. There is a number of tutorials on the net, but none of them described the full solution. So after getting it all to work, I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-196" title="Git, RedMine, Ruby, Rails on Dreamhost" src="http://www.ivankuznetsov.com/wp-content/uploads/git.png" alt="Git, RedMine, Ruby, Rails on Dreamhost" width="200" height="150" />The task is to have:<br />
- Redmine installation on redmine.mydomain.com<br />
- Several Git repositories on git.mydomain.com with different access rights to each one</p>
<p>This proved to be a non-trivial task. There is a number of tutorials on the net, but none of them described the full solution. So after getting it all to work, I decided to share all the tips and tricks. Feel free to comment, if you will find problems with the following set of instructions.<br />
<span id="more-195"></span>SSH to redmine.mydomain.com as a user that will be running Redmine (in the following examples it will be &#8216;redmine_user&#8217;).<br />
First, you need to compile openssl &#8211; it will be required for curl, git and redmine.</p>
<pre>mkdir ~/tmp
cd ~/tmp
wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz
tar xzvf openssl-0.9.8k.tar.gz
cd openssl-0.9.8k
./config shared zlib --prefix=$HOME/.packages
make
make install</pre>
<p>Let&#8217;s tell the world that we keep binaries and libraries also in the local directory. Edit ~/.bashrc (it is used by all non-login shells):</p>
<pre>export TZ='Europe/Helsinki'
export PATH="$HOME/.packages/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/.packages/lib"
export GEM_HOME="$HOME/.gems"
export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"
export PATH="$HOME/.packages/bin:$HOME/.gems/bin:$PATH"
export RUBYLIB="$HOME/.packages/lib:$RUBYLIB"
export LD_LIBRARY_PATH="$HOME/.packages/lib"

# this ensures our gem install processes don't get killed by the DreamHost police
alias gem="nice -n19 ~/.packages/bin/gem"</pre>
<p>(You can skip TZ &#8211; it is just usefule to have correct time set for your environment. Use tzselect to find out correct TZ string for your region)</p>
<p>And edit ~/.bash_profile (it is used by login shells):</p>
<pre>umask 002
PS1='[\h:$PWD]$ '
alias ll="ls -l"
EDITOR="/usr/bin/vim"
. .bashrc</pre>
<p>Now let&#8217;s apply the changes in active shell:</p>
<pre>cd ~ : . .bash_profile</pre>
<p>Then you need to compile curl, to be able to compile git with curl and execute clone commands on your server.</p>
<pre>cd ~/tmp
wget http://curl.haxx.se/download/curl-7.19.5.tar.gz
tar xzvf curl-7.19.5.tar.gz
cd curl-7.19.5
./configure --prefix=$HOME/.packages --with-ssl=$HOME/.packages
make
make install</pre>
<p>Now get and compile Git. If you are not using Dreamhost PS, you might want to compile it with NO_MMPAP=1, to reduce<br />
probability of git process getting killed by Dreamhost police robots due to extensive memory</p>
<pre>cd ~/tmp
wget http://www.kernel.org/pub/software/scm/git/git-1.6.4.tar.gz
tar xzvf git-1.6.4.tar.gz
cd git-1.6.4
./configure --prefix=$HOME/.packages --with-curl=$HOME/.packages
make
make install</pre>
<p>Let&#8217;s start with ruby and rails related stuff. First readline library is needed, for script/console to work.</p>
<pre>cd ~/tmp
wget http://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
tar xzvf readline-5.2.tar.gz
cd readline-5.2
./configure --prefix=$HOME/.packages
make
make install</pre>
<p>Install ruby:</p>
<pre>cd ~/tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
tar zxvf ruby-1.8.7-p72.tar.gz
cd ruby-1.8.7-p72
./configure --prefix=$HOME/.packages --with-openssl-dir=$HOME/.packages --with-readline-dir=$HOME/.packages
make
make install</pre>
<p>Install rubygems:</p>
<pre>cd ~/tmp
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar zxvf rubygems-1.3.5.tgz
cd rubygems-1.3.5
ruby setup.rb config --prefix=$HOME/.packages
ruby setup.rb setup
ruby setup.rb install</pre>
<p>Now you can install all required gems and freeze them if necessary.</p>
<p><strong>Installing RedMine</strong></p>
<p>Refer to <a href="http://wiki.dreamhost.com/Redmine" target="_blank">http://wiki.dreamhost.com/Redmine</a> for details.</p>
<p>But there&#8217;s one trick &#8211; if you want RedMine to use just compiled version of Git &#8211; edit in lib/redmine/scm/adapters/git_adapter.rb:</p>
<pre># Git executable name
GIT_BIN = "/home/username/.packages/bin/git"</pre>
<p>If this is not done, default Dreamhost git will be used (which is too old at the moment 1.4.4.4) and Git repository browsing will not work in RedMine<br />
(see <a href="http://groups.google.com/group/phusion-passenger/browse_thread/thread/5080d7c7cfbcf20e" target="_blank">http://groups.google.com/group/phusion-passenger/browse_thread/thread/5080d7c7cfbcf20e</a>).</p>
<p><strong>Setting up Git repository</strong></p>
<p>Refer to <a href="http://wiki.dreamhost.com/Git" target="_blank">http://wiki.dreamhost.com/Git</a> for details.</p>
<p>Couple of tricks here. There are bugs in WebDAV functionality in Ubuntu &#8211; so if you&#8217;re using it &#8211; launch Nautilus, use &#8220;File-&gt;Connect to server&#8230;&#8221; menu from there (not from the system menu), don&#8217;t enter user name in the dialog &#8211; leave it empty and enter it when you&#8217;re requested username and password in the next dialog.</p>
<p>When setting up WebDAV access rights, give access to user &#8220;redmine&#8221;.</p>
<p><strong>Setting Git repository copy for Redmine</strong></p>
<p>Create ~/.netrc for your redmine user on Dreamhost</p>
<p>Insert the following line in that file</p>
<pre>machine git.mydomain.com login redmine password [redmine_password]</pre>
<p>where redmine_password is the password you gave to user redmine in the previous step.<br />
.netrc will ensure that password is not asked when git is accessing the repository.<br />
You don&#8217;t need to bother about creating .netrc if you have a public repository (or at least available for cloning without password).</p>
<p><strong>Create a local copy of the repository</strong></p>
<p>For RedMine to be able to display Git repository, it needs to have a local clone of the repository.</p>
<pre>mkdir ~/git_project_clones
cd git_project_clones
git clone http://git.mydomain.com/repository_name</pre>
<p>Now you should have a local copy that can be used from RedMine.<br />
All you have left to do is to set up regular pulls from the master repository to this local copy. Use command</p>
<pre>crontab -e</pre>
<p>Add the following line to pull latest change into local copy every 5 minutes:</p>
<pre>*/5 * * * * cd /home/redmine_user/git_project_clones/repository_name &amp;&amp; /home/redmine_user/.packages/bin/git pull</pre>
<p>Make sure that you specify full path to git &#8211; otherwise it will execute Dreamhost default git 1.4.4.4 and command will fail with &#8220;refusing to create funny ref &#8216;remotes/origin/*&#8217; locally&#8221; error.</p>
<p>Save and exit cron editor.</p>
<p>(You might also want to check Redmine own wiki: <a href="http://www.redmine.org/wiki/redmine/HowTo_keep_in_sync_your_git_repository_for_redmine" target="_blank">http://www.redmine.org/wiki/redmine/HowTo_keep_in_sync_your_git_repository_for_redmine</a>)</p>
<p>Set repository in the settings of your project in RedMine: /home/redmine_user/git_project_clones/repository_name/.git</p>
<p>Now you need to manually update Git repository changesets in RedMine:</p>
<pre>cd ~/mydomain.com
script/runner "Repository.fetch_changesets" -e production</pre>
<p>And set a hook to your repository to do this every time repository is updated &#8211; edit ~/git_project_clones/repository_name/.git/hooks/post-update file and add the following command ther:</p>
<pre>cd /home/redmine_user/mydomain.com &amp;&amp; script/runner "Repository.fetch_changesets" -e production</pre>
<p>When writing this blogpost I found a lot of useful information on Dreamhost own wiki as well on these blog posts:<br />
<a href="http://www.wavethenavel.com/2008/09/08/bootstrapping-a-dreamhost-account-for-rails-and-git/" target="_blank"> http://www.wavethenavel.com/2008/09/08/bootstrapping-a-dreamhost-account-for-rails-and-git/</a><br />
<a href="http://juliobiason.net/2008/05/19/git-repositories-on-dreamhost-via-ssh/" target="_blank"> http://juliobiason.net/2008/05/19/git-repositories-on-dreamhost-via-ssh/</a><br />
<a href="http://www.simonecarletti.com/blog/2009/07/configuring-git-repository-with-redmine/" target="_blank"> http://www.simonecarletti.com/blog/2009/07/configuring-git-repository-with-redmine/</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.ivankuznetsov.com%2F2009%2F07%2Fsetting-up-ruby-rails-git-and-redmine-on-dreamhost.html&amp;linkname=Setting%20up%20Ruby%2C%20Rails%2C%20Git%20and%20Redmine%20on%20Dreamhost"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2009/07/setting-up-ruby-rails-git-and-redmine-on-dreamhost.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
