Nestacms with passenger, rvm, apache

Objective

To get Nesta to be served from Apache with Passenger.

Summary

About a couple months ago, I came across Nesta which is really awesome and really simple CMS built off the Sinatra framework. But I could not figure out how to host the application with Apache. Fast forward to this evening and I finally found a solution. If you have any suggestions on how it could be done different, please post a comment as I would like to hear about it.

Build

So! you want to build it. Ok, here are the steps I did:

  1. Install RVM and Ruby (I ended up with the single user install as you will notice)
  2. curl -L get.rvm.io | bash -s stable
  3. rvm requirements
  4. (install necessary stuff to compile ruby and gems)
  5. rvm install 1.9.2
  6. rvm use –default 1.9.2
  7. Install Nesta
  8. gem install nesta
  9. Create your site home and site itself
  10. mkdir /apps
  11. cd /apps
  12. nesta new mysite
  13. (take note that all additional steps use “/apps/mysite” as the nesta directory)
  14. Install Passenger
  15. gem install passenger
  16. passenger-install-apache2-module
  17. Apache config
  18. mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled /etc/httpd/mods-available /etc/httpd/mods-enabled
  19. Create the file /etc/httpd/mods-available/passenger.conf (see git gist below)
  20. Create the file /etc/httpd/sites-available/mysite (see git gist below)
  21. cd /etc/httpd/sites-enabled
  22. ln -s ../sites-available/mysite mysite
  23. cd /etc/httpd/mods-enabled
  24. ln -s ../mods-available/passenger.conf passenger.conf
  25. turn on NameVirtualHosts feature
  26. sudo /etc/init.d/httpd restart
  27. goto your new site!

Using the console with RedMine to find records or information

Some features of RedMine are not available for doing reporting. So I started to dig into the console interface and ran some of my own queries:

Starting the RedMine console (WARNING! Be careful!)

To start the RedMine console, change directories to your application base:

cd /usr/share/redmine-1.2

Now run the following command to get into the console:

RAILS_ENV=production ./script/console

This will get you into the Production side of your environment. If you want to use development area:

RAILS_ENV=development ./script/console

Running some queries:

Find all issues by their description only:

Issue.find(:all, :conditions => "description LIKE '%your_pattern%'")

Find all issues by their description only limited by project id:

Issue.find(:all, :conditions => "description LIKE '%your_pattern%' AND project_id = '5'")

Find spent hours by looking for a custom value in a issue:

hours = []
CustomValue.find(:all, :conditions => "custom_field_id = 35 AND value LIKE '%your_pattern%'").each do |c|
hours << Issue.find(c.customized_id).spent_hours
end

Find all issues that a specific user has commented on:

user_2 = []
Project.find(5).issues.each do |issue|
issue.journals.each do |journal|
if journal.user_id == 2
user_id << issue.id
end
end

Find list of users who contributed to an issue for a specific project:

results = Hash.new
Project.find(5).issues.find(:all).each do |issue|
people = []
issue.journals.each do |j|
people << user
end
results["#{issue}"] = people unless people.empty?
end

y results

Configuring rvm with ruby on rails with passenger and capistrano

This covers using the following software versions:

  • ruby-1.9.2-p318
  • passenger-3.0.11
  • rails 3.2.2
  • Apache 2.2

In short, the following steps are necessary:

  1. Install RVM with the multi user instructions
  2. Check requirements
    rvm requirements
  3. Install ruby 1.9.2
    rvm install 1.9.2
  4. Install passenger
    gem install passenger
  5. Load passenger into apache with passenger.conf
  6. Add a new user called ‘cap-deploy’
  7. Create a dir of /webapps and owned by the user and group of the apache process
  8. Create a dir of /webapps/yourrailsapp and the user and group of cap-deploy with perms of 775 (might be able to get away with less perms)
  9. Cap your rails application on your dev environment
  10. Add your rails app to a version management (I went with github) that is accessible by your hosting server
  11. Configure your version management to ignore the following files gitignore
  12. Add the following to your Cap file: Capfile
  13. Configure your /config/deploy.rb file with db support so that version control system does not share our db config: deploy.rb
  14. Run the cap and have fun!
  15. cap deploy:setup
  16. do first push
  17. cap deploy:cold
  18. do updates
  19. cap deploy