如何在WampServer旁边安装Ruby on Rails?
是否可以在WampServer上安装Ruby on Rails(并保留WampServer的Apache / MySQL安装)?
我在WampServer旁边安装了Ruby on Rails。 这是怎么做的:
在您自己的WampServer的安装库中替换以下文本中的C:\wamp\
。
安装Ruby:
- 下载Ruby。 使用Windows 二进制版本,而不是“一键安装程序”,因为它包含我们不需要的MySQL和Apache。
- 将zip解压缩到
C:\wamp\ruby\
。 -
在PATH环境变量中添加Ruby的bin存储库:
- 右键单击“计算机/属性”。
- 单击“高级系统设置”。
- 高级选项卡/环境变量。
- 将
;C:\wamp\ruby\bin
附加到Path变量。
安装DevKit:
下载DevKit:
- 将DevKit解压缩到
c:\wamp\ruby\DevKit
。 -
cd /dc:\wamp\ruby\DevKit
。 -
ruby dk.rb init
。- 将
- c:\wamp\ruby
到config.yml
。
- 将
-
ruby dk.rb install
安装Rails和Mongrel服务器:
-
打开命令行并键入:
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 -cc:\wamp\www\rails\hello -p 3001 -e development
-
启动Mongrel服务:
net start ruby-hello
您现在可以在http://localhost:3001/
访问您的Rails应用程序。
与Apache集成
-
在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(如果httpd.conf中包含extra / httpd-vhosts.conf):
ServerName hello.com ServerAlias *.hello.com ProxyPass / http://localhost:3001/ ProxyPassReverse / http://localhost:3001 -
将hello.com添加到您的hosts文件。 在记事本中打开
c:\windows\system32\drivers\etc\hosts
并添加以下行:127.0.0.1 www.hello.com hello.com
您现在可以访问http://www.hello.com ,它应该加载您的Rails应用程序。
参考文献:
是的,有InstantRails
这假设您正在尝试设置开发环境,因为将Windows和/或WAMP用于生产服务器没有多大意义。
您可以使用Ruby安装程序在Windows上轻松实现Ruby 。 还有一键安装程序 ,其中包含许多库(尽管您可以稍后使用rubygems安装这些库)。
你是正确的,因为你将Rails(和依赖项)安装为gem。
现在,对于Apache ……我建议你保留你的WAMP安装,而不是将它用于Ruby / Rails。 Ruby有一个名为WEBrick的内置Web服务器,还有另一个名为Mongrel的轻量级服务器(可作为gem使用)。 这些可以与Apache同时运行,Apache提供PHP内容,Mongrel / WEBrick提供Rails。 它们将在不同的端口上运行(Apache上80,Mongrel / WEBrick默认为3000),因此不应该有任何冲突。
这种方法有几个优点:
- 你不必弄乱你的WAMP安装并冒险搞砸了。
- 从不同语言运行应用程序可以分别保护它们。 例如,如果您的Rails应用程序崩溃了服务器,它将不会带来您的PHP内容,以防您同时运行它们。
- 第三,大多数流行的Rails IDE(RubyMine,Aptana等)都有Mongrel和WEBrick服务器的内置控件。 这意味着您将能够在IDE中启动/停止/重新启动服务器,以及显示输出/日志。 对于Windows中的Rails开发,我推荐RubyMine。
MySQL与Apache是分开的,因此无论哪个服务器正在为其内容提供服务,您的Rails应用程序都能够访问MySQL数据库。 当然,您必须至少运行MySQL版本的WAMP才能使其正常工作。
要在localhost(wampserver等)上安装+运行Ruby On Rails应用程序:
使用独立的Ruby Server安装:a) http://railsinstaller.org/en b) http://www.helicontech.com/zoo/install.html c) https://bitnami.com/stack/ruby
要么
1)安装WAMP (或等)
2)安装Ruby
3)打开… wamp \ bin \ apache \ apache XXXX \ conf \ httpd.conf ,然后搜索并替换
Options Indexes FollowSymLinks
同
Options Indexes FollowSymLinks ExecCGI
(或Options Indexes FollowSymLinks Includes ExecCGI
)
ps也是,查找并确保未注释LoadModule cgi_module 。
4)搜索和替换
# AddHandler cgi-script .cgi
用(…删除# )
AddHandler cgi-script .cgi
AddHandler cgi-script .rb
5)找到行: DirectoryIndex index.php index.php3 index.html index.htm
并在它们的末尾添加: index.cgi index.rb
现在, 重启Apache 。
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."
ps注意:(a)正确更改C:| Ruby ..路径到您的RUBY安装路径。 (b)为避免出现问题,请不要在路径中安装RUBY,其中任何“文件夹名称”都包含空格。 (c)在行首和印刷品之间不应有空格(……
7)打开http://localhost/sample.rb
这就是全部 !!
ps 注意,在使用.htaccess [在.rb目录中]时,你可能需要在.htaccess中插入这些行:
Options +ExecCGI
AddHandler cgi-script .rb