How to install Ruby on Rails alongside WampServer?

2019-01-12 21:33发布

问题:

Is is possible to install Ruby on Rails alongside WampServer (and keep WampServer's Apache/MySQL installs)?

回答1:

I installed Ruby on Rails alongside WampServer. Here is how to do it:

Replace C:\wamp\ in the following text by your own WampServer's install repository.

Installing Ruby:

  1. Download Ruby. Use the Windows binary version, not the "one click installer" because it contains MySQL and Apache which we don't need.
  2. Extract the zip to C:\wamp\ruby\.
  3. Add Ruby's bin repository in your PATH environment variable:

    1. Right click "Computer / Properties".
    2. Click "Advanced System Settings".
    3. Advanced tab / Environment Variables.
    4. Append ;C:\wamp\ruby\bin to the Path variable.

Installing DevKit:

Download DevKit:

  1. Extract DevKit to c:\wamp\ruby\DevKit.
  2. cd /d c:\wamp\ruby\DevKit.
  3. ruby dk.rb init.

    • Add - c:\wamp\ruby to the end of config.yml.
  4. ruby dk.rb install

Installing Rails and the Mongrel server:

  1. Open the command line and type:

    gem install rails
    
  2. Create your first Rails application by opening the command line from C:\wamp\www\rails\ and typing:

    rails hello
    
  3. Install the Mongrel server and Windows Mongrel service, making sure to run the command line as administrator:

    gem install mongrel and 
    gem install mongrel_service
    
  4. Install a Windows service for your Rails application:

    mongrel_rails service::install -N ruby-hello -c c:\wamp\www\rails\hello -p 3001 -e development
    
  5. Start your Mongrel service:

    net start ruby-hello
    

You can now access your Rails application at http://localhost:3001/.

Integrating with Apache

  1. Enable mod_proxy in httpd.conf

    Open httpd.conf (c:\wamp\bin\apache\Apache2.x.x\conf\httpd.conf) and uncomment the following line:

    LoadModule proxy_module modules/mod_proxy.so
    
  2. Forward your traffic to your Mongrel server. Add the following text to your httpd.conf (or extra/httpd-vhosts.conf if it's included in your httpd.conf):

    <VirtualHost *:80>
    ServerName hello.com
    ServerAlias *.hello.com
    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001
    </VirtualHost>
    
  3. Add hello.com to your hosts file. Open c:\windows\system32\drivers\etc\hosts in Notepad and add the following line:

    127.0.0.1 www.hello.com hello.com
    

You can now go to http://www.hello.com and it should load your Rails application.

References:

  • http://rubyinstaller.org/downloads
  • http://www.wampserver.com
  • http://www.ruby-lang.org
  • http://mongrel.rubyforge.org and http://mongrel.rubyforge.org/wiki/Win32


回答2:

Yes, There is InstantRails



回答3:

This is assuming you're trying to set up a development environment, because it doesn't make much sense to use Windows and/or WAMP for a production server.

You can instally Ruby rather easily on Windows using the Ruby installer. There's also the one-click installer which includes a number of libraries (though you can install these yourself with rubygems later).

You are correct in that you install Rails (and dependencies) as a gem.

Now, as for Apache... I'm going to suggest that you keep your WAMP installation and simply don't use it for Ruby/Rails. Ruby has a built-in web server called WEBrick, and there's another light-weight server called Mongrel (available as a gem). These can be run simultaneously with Apache, with Apache serving PHP content and Mongrel/WEBrick serving Rails. They'll run on different ports (Apache on 80, Mongrel/WEBrick on 3000 by default), so there shouldn't be any conflicts.

There are several advantages with this approach:

  1. You won't have to mess with your WAMP installation and risk screwing something up.
  2. Running applications from different languages separately protects them from each other. For example, if your Rails app crashes the server, it won't bring your PHP stuff down with it in case you're running both.
  3. Thirdly, most popular Rails IDEs (RubyMine, Aptana, etc) have built-in controls for both or one of the Mongrel and WEBrick servers. This means that you'll be able to start/stop/restart your server within the IDE, as well as display the output/logs. For Rails development in Windows, I recommend RubyMine.

MySQL is separate from Apache, so your Rails app will be able to access MySQL databases regardless of which server is serving its content. Naturally, you'll have to run at least the MySQL version of WAMP in order for it to work.



回答4:

To install+run Ruby On Rails application on localhost (wampserver or etc):

USE standalone Ruby Server installations: a) http://railsinstaller.org/en b) http://www.helicontech.com/zoo/install.html c) https://bitnami.com/stack/ruby


OR

1) Install WAMP (or etc)
2) Install Ruby
3) open ...wamp\bin\apache\apacheXXXX\conf\httpd.conf, then search & replace
Options Indexes FollowSymLinks
with
Options Indexes FollowSymLinks ExecCGI (or Options Indexes FollowSymLinks Includes ExecCGI)
p.s. also, Find & ensure that LoadModule cgi_module is NOT commented.

4) search & replace
#AddHandler cgi-script .cgi
with (...removing # )
AddHandler cgi-script .cgi
AddHandler cgi-script .rb

5) Find the line: DirectoryIndex index.php index.php3 index.html index.htm
and add in the end of them: index.cgi index.rb
Now, Restart Apache.

6) create a sample.rb (in /www root), with such content:

#!C:\Ruby200\bin\ruby\ruby.exe
puts "Content-type: text/html" #in newer version, might be puts("....")
puts ""
puts "Test Pageeeeeeeee."

p.s. NOTE: (a) Change C:|Ruby.. path to your RUBY installation path correctly. (b) To avoid problems, dont install RUBY in a path, wherein any "folder name" contains a space. (c) There should not be a space between the start of line and print(..

7) open http://localhost/sample.rb

THAT's all!!



p.s.note, in come cases, while using .htaccess [inside .rb directory], you might need to insert these lines in .htaccess:
Options +ExecCGI
AddHandler cgi-script .rb