Now that you have a proper rails and git stack in your remote server, it is time to get serious and start deploying. Because I have already set up the VirtualHosts for Passenger, I will be skipping that step. If you have missed that you might want to visit the Apache installing steps.

Deploying Rails to Centos 5

Before we install Passenger, let’s create a test application first. If you have made your directories already, check that it is /home/yourdomain.com/public

The path structure has to end in /public for Passenger to work.

Head to the directory root parent of yourdomain.com. In this case it should be

 cd /home

Delete the yourdomain.com folder for now. We will recreate it using Rails.

 rm -rf yourdomain.com

Now run the rails generator

 rails new yourdomain.com -d mysql

This tells rails to create an application using mySQL as the database.

cd yourdomain.com

Head into your rails application and edit the /config/database.yml file.

vim /config/database.yml

Scroll using your keyboard arrows to the production database and hit I to enter the credentials that you have created when you installed mySQL .

Now, install the mysql2 gem for this app.

sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

Ok now, to test if you can edit the application blindly without GUI. lol. Make some controllers, delete the public folder’s index.html Edit some routes and let it sit. For me, I just made a static controller with some static pages and a route to one of them. I also added some links here and there. A simple test app to check if everything is running fine when we install passenger.

When you are done, head to the root directory, domain.com folder and initialize git.

 git init

Now we can install Passenger.

gem install passenger

If you run into any missing dependencies just yum install them.

Passenger should install without a glitch. Next, we should install the module for passenger to work with Apache.

passenger-install-apache2-module

Halfway through, you will be asked to put some lines into your apache’s config file. Copy them. When it is done installing it will also ask you to put in the VirtualHost chunk of code, which we do not have to do since you already specified them when you install Apache earlier on the series. But if you haven’t, you can do so as well.

First let’s put in the LoadModules’ lines into apache’s config file.

vim /etc/httpd/conf/httpd.conf

If this is not the location that the config file resides in you can run a

 locate httpd.conf

to get the proper path.

Once you are in the file, scroll down to the chunk of LoadModules lines and paste in the Passenger’s LoadModules’ lines at the very end of the chunk. Finally scroll down all the way to your VirtualHosts chunk and make sure nothing is amiss.

Now, just restart your apache by running

httpd -k restart

Go to the domain in your browser and you should see your test app up and running. If you are greeted by Rails 404 page and you couldn’t figure out what is wrong with your application, you can head into /home/yourdomain.com/log/production.log to see the errors that is causing this problem.

Fix it and restart your apache. You should have your rails app up and ready to be replaced by your development app in your local server.

To push your app to the server using git you need a remote repository. In this case, you can set it up by installing Gitosis.
The workflow looks like this.
Local development app –push to–> Gitosis remote repo –used by Capistrano to deploy to–> Remote development app

Also, in dire times you might fix your remote app and you could do this:

Remote development app (changed) –push to –> Gitosis remote repo –fetched by–> Local development app