Git, Capistrano, Passenger, and Apache Questions

First, I'm trying to do the legwork with utilizing all 4 together
because many people say it's a good combination to use. I already have
apache setup (was using it with the PHP version of my site formerly).

I've installed all gems and dependencies that I need on my slice (using
slicehost).

I have a fully pushed git repository (master) on github (private git)
with one user. For sake of these questions the user on github is called
(liveuser). I followed the following guide to setup a user called
(gituser) on my slice:

http://articles.slicehost.com/2009/5/13/capistrano-series-setting-up-git

I just don't follow the logic of it. Perhaps it's because I don't
understand why I even need to use (any) of these utilities to run my
server. I feel like I have to perform 100 things just to get this
scenario working together. I'm sure it's nice when it's all setup and
working 100% but I'm a bit frustrated at this point.

Question One: Is there a (complete guide) that acts as a walk-through
for setting up apache/capistrano/passenger/git together?

development machine and not on the server. You deploy through git
directly to your server. I don't see any good documentation out there
that explains this in detail. If there were a deployment for dummies
book I'd buy it in a heartbeat.

My Scenario:

Windows Development machine with app
Full github private repository being pushed to from my development
machine
All tests well and am ready for deployment and production testing
Slicehost slice (server) with apache and passenger (passenger not setup
yet)

Question Two: Is there an optimal setup here? What are the exact
steps, in order for deploying? Apache configuration first? Passenger
configuration first? Github configuration first?

I will leave it at this for now. I'm sure I'm not the only one that has
pulled his or her hair out over a deployment phase and I'm certainly not
going to be the last. I think there should be some type of formalized
documentation on complete deployment (at least something that is up to
date and not 2 years old).

Thanks for the follow-up Marnen. Yeah I like to use parens and quotes
for emphasis - I'd much rather use quotes - but I don't see anything
about that here. Anyhoo, that's another issue altogether.

So, here's my logic and understanding of this subject and yes, it's not
very large.. heh.

From what I understand, Capistrano is the tool that is used to deploy
the application to your server. It has nothing to do with
apache/passenger etc. correct?

Secondly, passenger is a front-end piece and apache is the back-end
piece of the server setup correct? If I didn't want to use passenger, I
could use mongrel in it's place? Not saying I would do this but just
clarifying for understanding..

In order of priority configurations:

Apache first
Passenger Second
.. that handles the server end?

I believe where I'm getting confused is that I'm looking at all of it at
once and it's making my head hurt a bit.

Is there documentation on setting up apache with rails? Prepping? Link
please.

Is there documentation on setting up passenger with apache? Prepping?
Link please.

How does capistrano tie in with git and my server? For instance, I see
the following as an example configuration:

set :application, "ncaastatpages"
# GITHUB BELOW
# Set Putty True to instantiate a passphrase call
default_run_options[:pty] = true
# Set the git repository
set :repository, "git@github.com:myuser/ncaastatpages.git"
# Specify which subversion or repository SCM to use
set :scm, :git
# Set your GIT password
set :scm_passphrase, "mypassword"
# Set your GIT user (this might need to be the same all the way around)
set :user, "myuser"
# If you're using your own private keys for git
# ssh_options[:forward_agent] = true
# Set the branch type
set :branch, "master"
# Shallow cloning will do a clone each time, but will only get the first
tree, not all the parents trees, too.
# set :git_shallow_clone, 1
# If you're using git's submodule support for edge rails or merb, set
this guy to make sure the submodules "git" checked out.
set :git_enable_submodules, 1
# Set remote cache you want to only force new changes only, fetching
changed data
set :deploy_via, :remote_cache

# Set the role for your web server
role :web, "ncaastatpages.com"

I only see one repository (for my current git repo), but how does it
know where to send it to? I.e. where in capistrano do you tell it where
to deploy to? I don't see anywhere in here where I am setting my server
and the port. I use a different SSH port so I need to set that
somewhere too.

I've read the documentation but it doesn't appear to talk about this.
I'm not using Ruby EE by the way - just a heads up.

I commented everything myself above to show you what I believe is
happening. If I'm incorrect, please let me know. Let's bring this
topic closer to capistrano usage first and I'll work with one piece and
iron out the others after I get capistrano logic down.

Alpha Blue wrote:

Thanks for the follow-up Marnen. Yeah I like to use parens and quotes
for emphasis - I'd much rather use quotes - but I don't see anything
about that here.

Neither is correct for English.

Anyhoo, that's another issue altogether.

So it is. :slight_smile:

So, here's my logic and understanding of this subject and yes, it's not
very large.. heh.

From what I understand, Capistrano is the tool that is used to deploy
the application to your server. It has nothing to do with
apache/passenger etc. correct?

Yes. Cap just automates an SSH session to your server.

Secondly, passenger is a front-end piece and apache is the back-end
piece of the server setup correct? If I didn't want to use passenger, I
could use mongrel in it's place? Not saying I would do this but just
clarifying for understanding..

Also correct, although you'd have to play around with Apache proxies if
you did that.

You won't go far wrong if you think of Passenger as the Rails equivalent
of mod_php.

In order of priority configurations:

Apache first
Passenger Second
.. that handles the server end?

Right. (And Ruby EE if you're using it.)

I believe where I'm getting confused is that I'm looking at all of it at
once and it's making my head hurt a bit.

Is there documentation on setting up apache with rails? Prepping? Link
please.

Read the Passenger docs.

Is there documentation on setting up passenger with apache? Prepping?
Link please.

Read the Passenger docs.

How does capistrano tie in with git and my server? For instance, I see
the following as an example configuration:

set :application, "ncaastatpages"
# GITHUB BELOW
# Set Putty True to instantiate a passphrase call
default_run_options[:pty] = true
# Set the git repository
set :repository, "git@github.com:myuser/ncaastatpages.git"
# Specify which subversion or repository SCM to use
set :scm, :git
# Set your GIT password
set :scm_passphrase, "mypassword"
# Set your GIT user (this might need to be the same all the way around)
set :user, "myuser"
# If you're using your own private keys for git
# ssh_options[:forward_agent] = true
# Set the branch type
set :branch, "master"
# Shallow cloning will do a clone each time, but will only get the first
tree, not all the parents trees, too.
# set :git_shallow_clone, 1
# If you're using git's submodule support for edge rails or merb, set
this guy to make sure the submodules "git" checked out.
set :git_enable_submodules, 1
# Set remote cache you want to only force new changes only, fetching
changed data
set :deploy_via, :remote_cache

# Set the role for your web server
role :web, "ncaastatpages.com"

I only see one repository (for my current git repo), but how does it
know where to send it to? I.e. where in capistrano do you tell it where
to deploy to? I don't see anywhere in here where I am setting my server
and the port.

That's what role :web does.

I use a different SSH port so I need to set that
somewhere too.

Please read the Cap docs. I don't try to keep all the config variables
in my head, so I can't really help you.

I've read the documentation but it doesn't appear to talk about this.
I'm not using Ruby EE by the way - just a heads up.

Why not?

I commented everything myself above to show you what I believe is
happening. If I'm incorrect, please let me know. Let's bring this
topic closer to capistrano usage first and I'll work with one piece and
iron out the others after I get capistrano logic down.

Read the Cap docs.

Best,

From what I understand, Capistrano is the tool that is used to deploy
the application to your server. It has nothing to do with
apache/passenger etc. correct?

99% correct. You can (and will) tell Capistrano how to restart your webserver in order to pick up the latest deployed files (since Rails won't check for new files in production).

For Apache/Passenger this just amounts to adding the following to your deploy.rb file:

namespace :deploy do
   desc "Restarts your application."
   task :restart, :roles => :app, :except => { :no_release => true } do
     as = fetch(:runner, "app")
     via = fetch(:run_method, :sudo)
     invoke_command "touch #{current_path}/tmp/restart.txt", :via => via, :as => as
   end
end

Secondly, passenger is a front-end piece and apache is the back-end
piece of the server setup correct?

Sort of. Apache is the web server and is the *first* piece of software to handle any requests coming from the client. Passenger is an apache module that knows how to handle requests made to your Rails app. So Passenger is like mod_php, but for Rails.

If I didn't want to use passenger, I
could use mongrel in it's place? Not saying I would do this but just
clarifying for understanding..

Yes, you could. The Apache configuration would be a little bit different, but you're right in that you either use Passenger or you use Mongrel (or thin, etc.).

In order of priority configurations:

Apache first
Passenger Second
.. that handles the server end?

Yes.

Is there documentation on setting up apache with rails? Prepping? Link
please.

Is there documentation on setting up passenger with apache? Prepping?
Link please.

http://modrails.com/install.html
http://modrails.com/documentation/Users%20guide%20Apache.html

How does capistrano tie in with git and my server? For instance, I see
the following as an example configuration:

Seems you're missing the "deploy_to" line...

set :deploy_to, "/home/web/yourapp.com"

Google around and you'll find articles on how to get this working.

I've read the documentation but it doesn't appear to talk about this.
I'm not using Ruby EE by the way - just a heads up.

You don't need to. You can, but it's not necessary.

I commented everything myself above to show you what I believe is
happening. If I'm incorrect, please let me know. Let's bring this
topic closer to capistrano usage first and I'll work with one piece and
iron out the others after I get capistrano logic down.

http://articles.slicehost.com/2009/5/13/capistrano-series-setting-up-git

Also, if you're not, hop on the slicehost IRC chat... lots of helpful people there doing exactly what you're doing...

-philip

Thanks again Philip and Marnen,

So, the point I'm stuck at during this particular piece is really
understanding how github and capistrano work together.

For instance, my server user/password are completely different from
github user/password. Do these need to be the same?

And, if so, do I need to create a special user that has the same
credentials as my github account so that deployment works?

If the above is true, and my deploy_to is set in a specific user
directory, wouldn't the new user have to have write access to that
directory as well? These are some of the questions that are a bit
confusing to me. I could be overthinking this too much.

I'll look over the links you provided to see what I can figure out. I'm
usually very patient but when I have difficulty understanding all of the
various pieces, I can get a bit downtrodden. I don't mind doing the
work. I just need to understand the work I'm doing.

Thanks.

Thanks again Philip and Marnen,

So, the point I'm stuck at during this particular piece is really
understanding how github and capistrano work together.

For instance, my server user/password are completely different from
github user/password. Do these need to be the same?

And, if so, do I need to create a special user that has the same
credentials as my github account so that deployment works?

If the above is true, and my deploy_to is set in a specific user
directory, wouldn't the new user have to have write access to that
directory as well? These are some of the questions that are a bit
confusing to me. I could be overthinking this too much.

I'll look over the links you provided to see what I can figure out. I'm
usually very patient but when I have difficulty understanding all of the
various pieces, I can get a bit downtrodden. I don't mind doing the
work. I just need to understand the work I'm doing.

Been there! Once you get it working it all starts to make sense, but there are a lot of pieces...

http://github.com/guides/deploying-with-capistrano

-philip

1) How do I add plugins into github?

There's several ways... you can do it directly... I find a tool called 'braid' to be very handy.

2) How do I populate my production database?

Depends... if you're starting from scratch you could try:

cap deploy:migrate

Otherwise do it manually, but if you can get things setup so that 'cap deploy:migrations' works you'll find life much easier as you make changes down the road.

3) What do I do with capistrano and passenger when I update something
on my development side. Is it that I update on my side, push to github
and then run cap deploy:update?

Don't run deploy:update. Just run 'deploy' or 'deploy:migrations' (if you have migrations that need running). There's more to it than just updating the code. Capistrano will keep a backup of the old revision so you can easily revert (deploy:rollback) and will (or can) restart your web server, etc.

I only read the original post and then kind of just glanced through
the rest.

I think articles.slicehost.com has got the best articles in getting a
slice up and running with everything u need for a Rails app.
Ive gone through the process twice and it took me no more than 2/3
hours.

You would love this blog post though. Just one beautiful Cap file that
sets up your whole slice. Run it, sit back, sip coffee and wallow in
delight.

http://www.viget.com/extend/building-an-environment-from-scratch-with-capistrano-2/