如何加载用户的.bashrc到Apache下运行Ruby CGI脚本的一部分RVM? [英] How to load the RVM part of user's .bashrc to run Ruby CGI scripts under Apache?

查看:248
本文介绍了如何加载用户的.bashrc到Apache下运行Ruby CGI脚本的一部分RVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置在Ubuntu 12.04新的服务器,我开始使用RVM。

I've configured a new server on Ubuntu 12.04 and I started to use RVM.

我已经在我的用户下安装RVM(我自己,而不是使用sudo根)按照的瑞恩比格的指南,没有previous系统范围内安装了Ruby。所以,我没有在/ usr / bin中的任意红宝石。那么我的第一个任务是,以取代我所有的CGI脚本的家当线,从

I've installed RVM under my user (as myself, not as root with sudo) by following the Ryan Bigg's guide, with no previous system-wide installed Ruby. So, I didn't have any Ruby under /usr/bin. My first task then was to replace the shebang line of all my CGI scripts, from

!#/usr/bin/ruby

!#/usr/bin/env ruby

不过我的剧本没有在Apache下运行。在终端,我可以(通过键入 ./ index.cgi文件,例如)运行它们,而不是在一个浏览器。一个相关的注释:在两个用户是相同的,即,Apache用户是作为一个登录终端相同。通过PHP的测试,我检查了RVM环境(的最后几行的.bashrc )Apache下未加载。

However my scripts didn't run under Apache. In the terminal I could run them (by typing ./index.cgi, for example), but not over a browser. A relevant note: in both the user is the same, i.e., the Apache user is the same as the one logged on terminal. Through php tests, I've checked the RVM enviroment (last lines of .bashrc) was not loaded under Apache.

我看到的这个技巧对于RVM ,这表明把红宝石的特定版本的完整路径的家当线运行CGI脚本。如果你有不同版本的Ruby运行脚本这可能是有用的。但是,解决方案不适合我,因为我的脚本必须在不同的机器上运行,具有不同的用户和不同的路径。

I saw this tip for running CGI scripts with RVM, which suggests to put the complete path of specific version of Ruby in the shebang line. That can be useful if you have scripts which run on different versions of Ruby. But that solution doesn't work for me, because my scripts must run on different machines, with different users and different paths.

这对我的作品的解决方案是将所需要的红宝石版本的符号链接在/ usr / bin中:

The solution which works for me is to put a symlink of the desired Ruby version under /usr/bin:

sudo ln -s /home/apache_user/.rvm/rubies/ruby-1.8.7-p370/bin/ruby /usr/bin/ruby

但我想知道是否有更好的解决办法,因为我想这 RVM --default使用好过须藤LN -S

我在想:


  • 在启动时加载RVM环境(但我不知道如何做到这一点);

  • 加载RVM环境对每个Web请求(这会降低性能,我不知道如何配置Apache来做到这一点);

  • 也许RVM环境被加载,所有我必须做的是猜测相关变量的名称与 PassEnv 指令传递。但我对此表示怀疑。 (为什么阿帕奇将运行的.bashrc ,而不是像 CSH KSH ?)

  • loading the RVM Environment on startup (but I don't know how to achieve that);
  • loading the RVM Environment for each web request (which can degrade performance, and I don't know how to configure Apache to do that);
  • maybe the RVM Environment is loaded and all I must do is to guess the name of relevant variables to pass with PassEnv directive. But I doubt that. (Why Apache would run the .bashrc instead of another shell like csh or ksh?)

推荐答案

您总是可以做

sudo ln -s /usr/local/rvm/rubies/default/bin/ruby /usr/bin/ruby

这将RVM管理的Ruby的默认版本链接到的/ usr / bin中/红宝石,你将永远不会做任何事情。设置它和忘记它。

That will link the default version of the rvm-managed Ruby to /usr/bin/ruby and you will never have to do anything. set it and forget it.

这篇关于如何加载用户的.bashrc到Apache下运行Ruby CGI脚本的一部分RVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆