How-To: Add Ruby RVM, Rack and Passenger(mod_rails) to XAMPP
Posted: 29. December 2010 05:40
Start by following the How-To: Add Ruby-on-Rails to XAMPP
http://community.apachefriends.org/f/viewtopic.php?f=17&t=43516
You should now have Ruby and Rails installed and working in XAMPP.
To create a good RVM, Rack and Ruby on Rails working environment for XAMPP we need to set some environment variables:
Now source this file in every shell where you want to use RVM and Ruby on XAMPP:
To install Passenger (mod_rails):
To install the Passenger module (mod_rails) into Apache and configure it:
Let's add the proper PATH into Apache:
Restart Apache
Install Ruby Version Manager (RVM) (similar to Python's virtualenv):
Ref: http://rvm.beginrescueend.com/rvm/
(Lets you install multiple Ruby versions in development environments)
So let's install some Gems in our local development environment:
And setup a project tree:
Next, create a HelloWorld project:
browser to: http://localhost:8000
Move the smoketest page out of the way
Now, let's create our own Controller and View:
Check our Rack-based config file:
We don't need to change anything at the moment.
Create our databases:
Configure a 'root' route:
Serve it using rackup and WEBrick:
Now let's serve it with Apache:
IMPORTANT: we must set GEM load paths for Apache from our RVM environment:
And configure a Virtual Host:
if you need more options see:
http://wiki.rubyonrails.org/deployment/apache-passenger
http://www.modrails.com/documentation/U ... pache.html
And create a symlink from our 'public' folder into the DOCUMENT_ROOT tree:
Restart Apache
browser to: http://localhost:8000/HelloWorld
And we've got Apache serving our Rack-based Ruby-on-Rails app in XAMPP!
Some links to help you get started:
http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started
http://guides.rubyonrails.org/rails_on_rack.html
Enjoy
-Gerry
.
http://community.apachefriends.org/f/viewtopic.php?f=17&t=43516
You should now have Ruby and Rails installed and working in XAMPP.
To create a good RVM, Rack and Ruby on Rails working environment for XAMPP we need to set some environment variables:
- Code: Select all
echo "
export PATH=/opt/lampp/sbin:/opt/lampp/bin:/opt/lampp:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # loads Ruby Version Manager (RVM) into a shell session.
" > ~/.bashrc_xampp_ruby
# do this for 'root' user as well as regular user
# plus I would recommend you add XAMPP into your $PS1 prompt somewhere
Now source this file in every shell where you want to use RVM and Ruby on XAMPP:
- Code: Select all
source ~/.bashrc_xampp_ruby
To install Passenger (mod_rails):
- Code: Select all
sudo gem install passenger
To install the Passenger module (mod_rails) into Apache and configure it:
- Code: Select all
sudo passenger-install-apache2-module
whatever the passenger-install-apache2-module output shows, add it to your Apache /opt/lampp/etc/httpd.conf
Let's add the proper PATH into Apache:
- Code: Select all
sudo echo '
PATH="/opt/lampp/sbin:/opt/lampp/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:$PATH"
export PATH' >> /opt/lampp/bin/envvars
Restart Apache
- Code: Select all
/opt/lampp/lampp restartapache
Install Ruby Version Manager (RVM) (similar to Python's virtualenv):
Ref: http://rvm.beginrescueend.com/rvm/
(Lets you install multiple Ruby versions in development environments)
- Code: Select all
cd $HOME
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-latest )
source $HOME/.rvm/scripts/rvm
rvm notes # read
rvm install 1.9.2
rvm use 1.9.2
which ruby
ruby -v
rvm info
rvm debug
So let's install some Gems in our local development environment:
- Code: Select all
rvm use 1.9.2
gem install rails # rack comes in with rails now
gem install mysql mysql2
And setup a project tree:
- Code: Select all
mkdir -p projects/ruby/rack # rack can be used without rails
mkdir -p projects/ruby/rails/rack
Next, create a HelloWorld project:
- Code: Select all
cd projects/ruby/rails/rack
rails new HelloWorld -d mysql
cd HelloWorld
rails server -p 8000 # see the smoketest page (Press Ctrl-c to exit)
browser to: http://localhost:8000
Move the smoketest page out of the way
- Code: Select all
mv public/index.html public/index.html.moved
Now, let's create our own Controller and View:
- Code: Select all
rails generate controller hello index
echo "<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello#index</h1>
<p>Find me in app/views/hello/index.html.erb</p>
<h2>Hello World</h2>
<p>Hello from Rack and Ruby on Rails!</p>
</body>" > app/views/hello/index.html.erb
Check our Rack-based config file:
We don't need to change anything at the moment.
- Code: Select all
$EDITOR config.ru
Create our databases:
- Code: Select all
rake db:create
Configure a 'root' route:
- Code: Select all
$EDITOR config/routes.rb
# add: root :to => "hello#index"
Serve it using rackup and WEBrick:
- Code: Select all
rackup -p 8000 # (Press Ctrl-c to exit)
Now let's serve it with Apache:
IMPORTANT: we must set GEM load paths for Apache from our RVM environment:
- Code: Select all
env | grep GEM # check for GEM vars in your environment
Add the following (please replace USER with your username):
ENV['GEM_HOME']='/home/USER/.rvm/gems/ruby-1.9.2-p136'
ENV['GEM_PATH']='/home/USER/.rvm/gems/ruby-1.9.2-p136:/home/USER/.rvm/gems/ruby-1.9.2-p136@global'
$EDITOR config/setup_load_paths.rb
And configure a Virtual Host:
if you need more options see:
http://wiki.rubyonrails.org/deployment/apache-passenger
http://www.modrails.com/documentation/U ... pache.html
- Code: Select all
echo '
Listen 8000
<VirtualHost *:8000 >
ServerName localhost
DocumentRoot /opt/lampp/htdocs/rails
RailsEnv development
# Deploy in Sub-URI: (requires symlink
# from Rack app "public" directory to DOCUMENT_ROOT+RailsBaseURI )
RailsBaseURI /HelloWorld
# ln -s $HOME/projects/ruby/rails/rack/HelloWorld/public /opt/lampp/htdocs/rails/HelloWorld
<Directory "/opt/lampp/htdocs/rails/HelloWorld" >
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>' >> /opt/lampp/etc/httpd.conf
And create a symlink from our 'public' folder into the DOCUMENT_ROOT tree:
- Code: Select all
mkdir /opt/lampp/htdocs/rails
ln -s $HOME/projects/ruby/rails/rack/HelloWorld/public /opt/lampp/htdocs/rails/HelloWorld
Restart Apache
- Code: Select all
/opt/lampp/lampp restartapache
browser to: http://localhost:8000/HelloWorld
And we've got Apache serving our Rack-based Ruby-on-Rails app in XAMPP!
Some links to help you get started:
http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started
http://guides.rubyonrails.org/rails_on_rack.html
Enjoy
-Gerry
.