How-To: Add Ruby RVM, Rack and Passenger(mod_rails) to XAMPP

Problems with the Linux version of XAMPP, questions, comments, and anything related.

How-To: Add Ruby RVM, Rack and Passenger(mod_rails) to XAMPP

Postby greno » 29. December 2010 05:40

Start by following the How-To: Add Ruby-on-Rails to XAMPP

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 '                     
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):
(Lets you install multiple Ruby versions in development environments)
Code: Select all
cd $HOME
bash < <( curl )
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>
<title>Hello World!</title>
<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

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):
$EDITOR config/setup_load_paths.rb

And configure a Virtual Host:
if you need more options see: ... 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

</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:



Posts: 54
Joined: 04. October 2006 19:25

Re: How-To: Add Ruby RVM, Rack and Passenger(mod_rails) to X

Postby ksager » 22. February 2011 16:34

Hi Gerry and friends ;-)
I successfully completed part 1 of this series "Add Ruby-on-Rails to XAMPP"

When I attempted this Part II "Add Ruby RVM, Rack and Passenger(mod_rails) to XAMPP," I experienced a problem at "RESTART APACHE." Now, even if a reboot the machine, if I attempt to start xampp, I receive the message, "XAMPP: Another web server daemon is already running." MySql and Xampp otherwise start. Of course any attempt to restart apache yields the exact same message.

Upon installing Phusion per directions in this tutorial, I was directed by Phusion to do the following (which I did):
"Installation instructions for required software
* To install Curl development headers with SSL support:
Please run apt-get install libcurl4-openssl-dev or libcurl4-gnutls-dev, whichever you prefer.
* To install Apache 2:
Please run apt-get install apache2-mpm-prefork as root.
* To install Apache 2 development headers:
Please run apt-get install apache2-prefork-dev as root.
* To install Apache Portable Runtime (APR) development headers:
Please run apt-get install libapr1-dev as root.
* To install Apache Portable Runtime Utility (APU) development headers:
Please run apt-get install libaprutil1-dev as root. "

I also added the following lines to /opt/lampp/etc/httpd.conf at the direction of Phusion:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2
PassengerRuby /usr/bin/ruby1.8

Is there any clue from this what could be going on? I also noticed in part 1 of the series that test used webrick; but I do not believe that stays resident after reboot. I have been unable to find a clear way to identify what the other server is running. I am suspicious that it is another instance of Apache per the changes Phusion requested above. Any help is appreciated.
Posts: 3
Joined: 14. February 2011 19:21

Re: How-To: Add Ruby RVM, Rack and Passenger(mod_rails) to X

Postby ksager » 22. February 2011 16:47

OK More information for the reply above:
It was definitely apache 2 already running, probably per the "install apache 2" directive from Phusion.

I attempted sudo /etc/init.d/apache2 stop to stop apache 2
to see if I could then start xampp.

Then, attempting to start xampp yielded:
Starting XAMPP for Linux 1.7.4...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Error 1! Couldn't start Apache!
XAMPP: Starting diagnose...
XAMPP: Sorry, I've no idea what's going wrong.
XAMPP: Please contact our forum
XAMPP: XAMPP-MySQL is already running.
XAMPP for Linux started.
Gotta love an error message that says "sorry, I've no idea what's going wrong."

What I am taking from all this is that Phusion does not recognize an existing Xampp/Apache installation on Ubuntu 10.10. Any suggestions greatly appreciated. The first tutorial was very helpful and I like the idea of an integrated ruby-xampp development environment that will offer continued access to php. If no ideas...thanks for putting this up for folks anyway. Great idea!
Posts: 3
Joined: 14. February 2011 19:21

Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 7 guests