Setting Up Ubuntu 12.04 with Ruby 1.9.3, Rails, Nginx, Passenger, and PostgreSQL or MySQL

Posted May 7, 2012 under Rails

With the recent release of Ubuntu 12.04, we’ve got an even easier way to setup our webserver. Let me walk you through the steps:

Create Our Deploy User

One of the first things we want to make sure we get done is that we have a deploy user. This going to be the user that deploys the website and the same user that the website is run as.

sudo adduser deploy

Update and install our dependencies

This downloads the latest list of available software versions. We’ll install our build dependencies for later.

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core

Install Ruby 1.9.3

We’re going to install Ruby 1.9.3 from source. Note that -p194 may not be the latest version of Ruby. Check out ruby-lang.org to get the latest version and replace it in the following commands:

wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure
make
sudo make install
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
sudo gem install bundler

Install Nginx with Passenger

Since we’ll be using Nginx for serving our application, we’re going to install it using the latest package from a user repository:

sudo gem install passenger
sudo passenger-install-nginx-module
# Choose "download, compile, and install Nginx for me"
# Accept defaults for any other questions it asks you

Next we want to setup a script to allow us to control Nginx. We’re going to grab this from Linode:

wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

You can now control Nginx with this script. To start and stop the server manually, you run:

sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start

We can verify nginx is running by opening up Firefox and going to http://localhost

After installation, you’ll get some tips on how to configure an Nginx server to listen on a domain and enable passenger for it. You’ll want to save this for later when you setup your deployment scripts. The root path there will be the public directory where you setup your Rails app folder.

One of the first things you want to do is edit the nginx.conf so that you can tell it to run as the deploy user. This file will be /opt/nginx/conf/nginx.conf and you can add this as the first line:

user deploy staff;

Alternative: Nginx With Unicorn

An alternative to Passenger is to install Nginx from it’s PPA and use Unicorn instead. This is preferred, but it takes a bit more setup. I won’t get too much into this, but you can install just plain Nginx with the following commands:

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start

After this, I recommend checking out Deploying To A VPS by Ryan Bates for setting up Unicorn.

Setup your database

Our next step is installing our database server. I’d recommend using PostgreSQL but many of you may prefer MySQL. Take your pick:

MySQL

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

OR

PostgreSQL 9.1.3

sudo apt-get -y install postgresql libpq-dev

Node.js for the Rails asset pipeline

One of the other things you’ll want is Node.js. This will help us do the compiling of assets on deployments. It’s a pretty quick installation to get the latest version:

sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs

Configure Your Rails App

You’ll need to get a copy of your rails application on the webserver. The best place to do this is to store it in the home directory of the deploy user. I recommend using Capistrano to set this up. Afterwards, you can modify your /opt/nginx/conf/nginx.conf file to contain a new passenger server like so:

server {
	listen 80;
	server_name example.com;
	root /home/deploy/myapplication/public;   # <--- be sure to point to 'public'!
	passenger_enabled on;
}

Just change the application folder name and the server name and then restart the nginx service.

Conclusion

And there you have it! Your server is configured and ready for deployments.


Don’t Settle

Posted April 18, 2012 under General

“You’ve got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don’t settle.”

Steve Jobs


Flip A Coin

Posted April 16, 2012 under General

“When you have to make a hard decision, flip a coin.
When that coin is in the air, you suddenly know what you’re hoping for.”

This quote has hit home on several occasions. There have been a few times in life where I was pretty sure I didn’t want to continue. The problem was that it was easier to continue than to sit down and make the realization I needed a change.

For most decisions, you probably lean to one side whether you want to admit it or not. Have someone else ask you the decision and flip the coin. The answer now feels out of your control. Allow yourself a second to think before they show you the result. It quickly becomes clear that you want a specific result.

Decisions can be very hard. Especially when you can’t make up your mind.

Robbie Abed recently discussed a situation he was in previously at a job he didn’t like. This same situation happened to me several months ago. I didn’t want to come into work anymore and secretly wished I had a reason to leave. About a month after realizing this, I left as well.

In one of his many amazing blog posts, Derek Sivers talks about decision making by either saying HELL YEAH or no. Now this works wonderfully if you’re not making a decision about starting something new. It’s easy to dismiss this tactic when you’re miserable. When you’re doing something soul sucking, you sometimes can’t bring yourself to say “hell yeah!” anymore. Flipping a coin can help you realize what you want to say “hell yeah!” to.

The truth is you’re always better off

When it comes to making a decision about pursuing a new path or staying, it’s always best to go with your gut feeling.

Do you immediately lean towards staying? Then you need to bring it up to your boss and coworkers about changes that need to be made. Truth is, you’re happy where you’re at, mostly. Some things aren’t working, so bring it up and get them fixed.

If you lean the other direction, then quit. You’ve always wanted to build things? Then go. In the world we live in today, you’ve got nothing stopping you. You can travel around the world in a matter of hours. A team of 13 can sell their company for $1 billion after just 2 years.

There is NO REASON you shouldn’t be doing what makes you excited day in and day out.


Of Course

Posted April 9, 2012 under General

Most companies (including web startups), he said, are looking to “wow” with their products, when in reality what they should be looking for is an “‘of course’ reaction from their users.”

Puzzled, I looked at him. And then it hit me: Great design means that one look and the end user reacts by knowing what to do with a knob or a button, without as much as even thinking about it. Of course this knob is what turns the volume up, or brings up the home screen.

This of course factor is at the heart of every great design — from the iPhone to the Braun alarm radio. And it’s an important lesson that every startup and entrepreneur should remember. Whether your company is making a physical product or a web service or mobile application, it’s essential for you to think about design.

Christian Lindholm

Source: http://om.co/2012/04/05/the-of-course-principle-of-design/


Maybe You’re Just Making Excuses

Posted April 2, 2012 under General

Successful people must have a property about them that makes them successful. The media likes to explain this as being magical. This is rarely the case. What you don’t see is the years of hard work put into learning the ropes.

Rovio spent 8 years developing games before Angry Birds was a hit. Zuckerberg spent hours upon hours getting good at programming before he could actually build the first version of Facebook. Steve Jobs got fired from Apple before he came back and turned the company around. Failure and hard work are things they embraced.

I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times, I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.
Michael Jordan

Failure is just a part of life. Don’t fear it. Maybe you’re just making excuses.


« Older |