如何在 WampServer 旁边安装 Ruby on Rails?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2025449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install Ruby on Rails alongside WampServer?
提问by Olivier Lalonde
Is is possible to install Ruby on Rails alongside WampServer(and keep WampServer's Apache/MySQL installs)?
是否可以将 Ruby on Rails 与WampServer一起安装(并保留 WampServer 的 Apache/MySQL 安装)?
回答by Olivier Lalonde
I installed Ruby on Rails alongside WampServer. Here is how to do it:
我在 WampServer 旁边安装了 Ruby on Rails。这是如何做到的:
Replace C:\wamp\in the following text by your own WampServer's install repository.
C:\wamp\在以下文本中替换为您自己的 WampServer 的安装存储库。
Installing Ruby:
安装红宝石:
- Download Ruby. Use the Windows binaryversion, not the "one click installer" because it contains MySQL and Apache which we don't need.
- Extract the zip to
C:\wamp\ruby\. Add Ruby's bin repository in your PATH environment variable:
- Right click "Computer / Properties".
- Click "Advanced System Settings".
- Advanced tab / Environment Variables.
- Append
;C:\wamp\ruby\binto the Path variable.
- 下载红宝石。使用 Windows二进制版本,而不是“一键安装程序”,因为它包含我们不需要的 MySQL 和 Apache。
- 将 zip 解压缩到
C:\wamp\ruby\. 在 PATH 环境变量中添加 Ruby 的 bin 存储库:
- 右键单击“计算机/属性”。
- 点击“高级系统设置”。
- 高级选项卡/环境变量。
- 附加
;C:\wamp\ruby\bin到 Path 变量。
Installing DevKit:
安装开发套件:
Download DevKit:
下载开发套件:
- Extract DevKit to
c:\wamp\ruby\DevKit. cd /d c:\wamp\ruby\DevKit.ruby dk.rb init.- Add
- c:\wamp\rubyto the end ofconfig.yml.
- Add
ruby dk.rb install
- 将 DevKit 提取到
c:\wamp\ruby\DevKit. cd /d c:\wamp\ruby\DevKit.ruby dk.rb init.- 添加
- c:\wamp\ruby到config.yml.
- 添加
ruby dk.rb install
Installing Rails and the Mongrel server:
安装 Rails 和 Mongrel 服务器:
Open the command line and type:
gem install railsCreate your first Rails application by opening the command line from
C:\wamp\www\rails\and typing:rails helloInstall the Mongrel server and Windows Mongrel service, making sure to run the command line as administrator:
gem install mongrel and gem install mongrel_serviceInstall a Windows service for your Rails application:
mongrel_rails service::install -N ruby-hello -c c:\wamp\www\rails\hello -p 3001 -e developmentStart your Mongrel service:
net start ruby-hello
打开命令行并输入:
gem install rails通过打开命令行
C:\wamp\www\rails\并键入以下内容来创建您的第一个 Rails 应用程序:rails hello安装 Mongrel 服务器和 Windows Mongrel 服务,确保以管理员身份运行命令行:
gem install mongrel and gem install mongrel_service为您的 Rails 应用程序安装 Windows 服务:
mongrel_rails service::install -N ruby-hello -c c:\wamp\www\rails\hello -p 3001 -e development启动您的 Mongrel 服务:
net start ruby-hello
You can now access your Rails application at http://localhost:3001/.
您现在可以访问您的 Rails 应用程序http://localhost:3001/。
Integrating with Apache
与 Apache 集成
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.soForward 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>Add hello.com to your hosts file. Open
c:\windows\system32\drivers\etc\hostsin Notepad and add the following line:127.0.0.1 www.hello.com hello.com
在 httpd.conf 中启用 mod_proxy
打开 httpd.conf (c:\wamp\bin\apache\Apache2.xx\conf\httpd.conf) 并取消注释以下行:
LoadModule proxy_module modules/mod_proxy.so将您的流量转发到您的 Mongrel 服务器。将以下文本添加到您的 httpd.conf(或 extra/httpd-vhosts.conf,如果它包含在您的 httpd.conf 中):
<VirtualHost *:80> ServerName hello.com ServerAlias *.hello.com ProxyPass / http://localhost:3001/ ProxyPassReverse / http://localhost:3001 </VirtualHost>将 hello.com 添加到您的主机文件中。
c:\windows\system32\drivers\etc\hosts在记事本中打开并添加以下行:127.0.0.1 www.hello.com hello.com
You can now go to http://www.hello.comand it should load your Rails application.
您现在可以访问http://www.hello.com,它应该会加载您的 Rails 应用程序。
References:
参考:
回答by YOU
Yes, There is InstantRails
是的,有InstantRails
回答by vonconrad
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.
这是假设您正在尝试设置开发环境,因为将 Windows 和/或 WAMP 用于生产服务器没有多大意义。
You can instally Ruby rather easily on Windows using the Ruby installer. There's also the one-click installerwhich includes a number of libraries (though you can install these yourself with rubygems later).
您可以使用Ruby 安装程序在 Windows 上轻松安装 Ruby。还有一键安装程序,其中包括许多库(尽管您可以稍后使用 rubygems 自己安装这些库)。
You are correct in that you install Rails (and dependencies) as a gem.
您将 Rails(和依赖项)安装为 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.
现在,至于 Apache...我将建议您保留 WAMP 安装并且不要将其用于 Ruby/Rails。Ruby 有一个名为 WEBrick 的内置 Web 服务器,还有另一个名为 Mongrel(作为 gem 提供)的轻量级服务器。这些可以与 Apache 同时运行,Apache 为 PHP 内容提供服务,Mongrel/WEBrick 为 Rails 提供服务。它们将在不同的端口上运行(Apache 在 80 上,Mongrel/WEBrick 默认在 3000 上),所以不应该有任何冲突。
There are several advantages with this approach:
这种方法有几个优点:
- You won't have to mess with your WAMP installation and risk screwing something up.
- 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.
- 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.
- 您不必弄乱您的 WAMP 安装并冒着搞砸的风险。
- 分别运行来自不同语言的应用程序可以相互保护它们。例如,如果您的 Rails 应用程序使服务器崩溃,则在您同时运行这两个应用程序的情况下,它不会使您的 PHP 内容崩溃。
- 第三,大多数流行的 Rails IDE(RubyMine、Aptana 等)都具有用于 Mongrel 和 WEBrick 服务器或其中之一的内置控件。这意味着您将能够在 IDE 中启动/停止/重新启动服务器,以及显示输出/日志。对于 Windows 中的 Rails 开发,我推荐 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.
MySQL 与 Apache 是分开的,因此您的 Rails 应用程序将能够访问 MySQL 数据库,而不管哪个服务器正在为其内容提供服务。当然,您必须至少运行 WAMP 的 MySQL 版本才能使其工作。
回答by T.Todua
To install+run Ruby On Railsapplication on localhost (wampserver or etc):
在本地主机(wampserver 等)上安装+运行Ruby On Rails应用程序:
USE standalone Ruby Server installations: a) http://railsinstaller.org/enb) http://www.helicontech.com/zoo/install.htmlc) https://bitnami.com/stack/ruby
使用独立的 Ruby 服务器安装:a) http://railsinstaller.org/enb) http://www.helicontech.com/zoo/install.htmlc) 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_moduleis NOT commented.
或
1) 安装WAMP(或等)
2) 安装Ruby
3) 打开 ...wamp\bin\apache\apache XXXX\conf\ httpd.conf,然后搜索并替换
Options Indexes FollowSymLinks
为
(或)
ps,查找并确保LoadModule cgi_module没有注释。Options Indexes FollowSymLinks ExecCGIOptions Indexes FollowSymLinks Includes ExecCGI
4) search & replace
#AddHandler cgi-script .cgi
with (...removing #)
AddHandler cgi-script .cgiAddHandler cgi-script .rb
4) 搜索并替换
#AddHandler cgi-script .cgi
为 (...removing #)
AddHandler cgi-script .cgiAddHandler 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.
5) 找到这一行:
DirectoryIndex index.php index.php3 index.html index.htm
并在它们的末尾添加: index.cgi index.rb
Now, Restart Apache。
6) create a sample.rb(in /www root), with such content:
6)创建一个sample.rb(在/www root中),内容如下:
#!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(..
ps 注意:(a) 将C:|Ruby..路径正确更改为您的 RUBY 安装路径。(b) 为避免出现问题,不要在路径中安装 RUBY,其中任何“文件夹名称”都包含空格。(c) 行首和print(..
7) open http://localhost/sample.rb
7) 打开 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 +ExecCGIAddHandler cgi-script .rb
ps注意,在某些情况下,在使用 .htaccess [inside .rb directory] 时,您可能需要在 .htaccess 中插入这些行:Options +ExecCGIAddHandler cgi-script .rb

