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
- Part 1 // Apache
- Part 2 // mySQL
- Part 3 // Git
- Part 4 // Ruby, Gems & Rails
- You are here!
- Part 6 // Gitosis
- Part 7 // Capistrano
Before we install Passenger, let’s create a test application first. If you have made your directories already, check that it is
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 [shell] cd /home[/shell]
yourdomain.com folder for now. We will recreate it using Rails.[shell] rm -rf yourdomain.com[/shell]
Now run the rails generator[shell] rails new yourdomain.com -d mysql[/shell] This tells rails to create an application using mySQL as the database.
Head into your rails application and edit the
/config/database.yml file. [shell]vim /config/database.yml[/shell]
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.[shell]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. [shell] git init[/shell]
Now we can install Passenger. [shell]gem install passenger[/shell] 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.[shell]passenger-install-apache2-module[/shell]
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. [shell]vim /etc/httpd/conf/httpd.conf[/shell] If this is not the location that the config file resides in you can run a [shell] locate httpd.conf[/shell] 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 [shell]httpd -k restart[/shell]
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