Production Server with Rails and Phusion Passenger
Posted: June 21st, 2011 | Author: Vincent | Filed under: Linux, Ruby, System | No Comments »First you need to install RVM, ruby, rubygem, rails, with LAMP already installed too.
rvmsudo passenger-install-apache2-module
# to find out where apache config file is
apachectl -V | grep SERVER_CONFIG_FILE
# load modules in Apache config (this may vary)
LoadModule passenger_module /home/vincent/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /home/vincent/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7
PassengerRuby /home/vincent/.rvm/wrappers/ruby-1.9.2-p180/ruby
# now this is an exmple of apache virtualhost
<VirtualHost *:80>
DocumentRoot /home/www-data/depot/public
ServerName appname.myserver.com
<Directory /home/www-data/depot/public>
AllowOverride all
Options -MultiViews
</Directory>
# Speeds up spawn time tremendously -- if your app is compatible.
# RMagick seems to be incompatible with smart spawning
RailsSpawnMethod smart
# Keep the application instances alive longer. Default is 300 (seconds)
PassengerPoolIdleTime 1000
# Keep the spawners alive, which speeds up spawning a new Application
# listener after a period of inactivity at the expense of memory.
RailsAppSpawnerIdleTime 0
# Additionally keep a copy of the Rails framework in memory. If you're
# using multiple apps on the same version of Rails, this will speed up
# the creation of new RailsAppSpawners. This isn't necessary if you're
# only running one or 2 applications, or if your applications use
# different versions of Rails.
RailsFrameworkSpawnerIdleTime 0
# Just in case you're leaking memory, restart a listener
# after processing 5000 requests
PassengerMaxRequests 5000
# only check for restart.txt et al up to once every 5 seconds,
# instead of once per processed request
PassengerStatThrottleRate 5
</VirtualHost>
Create the database needed for the new app, update config/database.yml content to allow app to connect to database on the production server.
Once the new rails app is uploaded to the server:
# install/update bundle cd appfolder/ bundle install # now setup database table and data cd appfolder/ rake db:setup RAILS_ENV=production
Next you use a2ensite and /etc/init.d/apache restart to reload the new site.
Leave a Reply