www-data 在 vagrant 配置的 virtualbox 上找不到 ruby gem

www-data can't find the ruby gems on vagrant configured virtualbox

我正在尝试使用 Vag运行t 和 VirtualBox 获取虚拟服务器 运行。对于 VirtualBox,我使用的是 scotch/box,它获得了 运行 的所有基本内容 ubuntu 服务器和一些组件(apache、mysql、php 等。 ) 更多关于 scotchbox 的信息可以在这里找到。

现在我启动了服务器 运行(运行 一个 Yii2 应用程序)但是应用程序一启动我就收到一条 Yii 错误消息 sh: 1: sass: not found 并且因此SASS 文件无法转换为 CSS。所以我回到我的服务器检查是否安装了 sass,没有,所以我 运行 命令 gem install sass 然后安装了 sass。 gem list sass -i 返回真值。

但是问题依旧,sass找不到。我回到我的控制台,当然 apache 是由用户 www-data 运行 并且我使用 vag运行t 用户登录到 ssh。这对我来说有点模糊。在 apache 服务的环境变量中,我添加了 ruby 和 gem 的路径。但是 www-data 用户仍然找不到 sass 命令或 gem 命令甚至 ruby 命令。

我还尝试将 apache 服务的所有者从 www-data 更改为 vag运行t 用户,这确实有点帮助,但这不是我想要接受的解决方案。我想要一个解决方案,即 apache 服务由 www-data 用户拥有,而不是像 vag运行t.

这样的 root 用户

如果需要添加更多数据,请告诉我。

环境变量文件

    envvars - default environment variables for apache2ctl

# this won't be correct after changing uid
unset HOME

# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
    SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
    SUFFIX=
fi

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy+1
export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale

export LANG

## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'

## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'

## If you would like to pass arguments to the web server, add them below
## to the APACHE_ARGUMENTS environment.
#export APACHE_ARGUMENTS=''

## Enable the debug mode for maintainer scripts.
## This will produce a verbose output on package installations of web server modules and web application
## installations which interact with Apache
#export APACHE2_MAINTSCRIPT_DEBUG=1
export GEM_HOME=/home/vagrant/.rvm/gems/ruby-2.1.3
export GEM_PATH=/home/vagrant/.rvm/gems/ruby-2.1.3:/home/vagrant/.rvm/gems/ruby-2.1.3@global
export MY_RUBY_HOME=/home/vagrant/.rvm/rubies/ruby-2.1.3
export IRBRC=/home/vagrant/.rvm/rubies/ruby-2.1.3/.irbrc
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

看看apache使用的PATH是否真的被你对envvars文件的调整修改了。您可以通过简单地放置 运行 这个 php 代码来做到这一点: var_dump(getenv("PATH")); die; 我遇到了完全相同的问题。经过很长时间的尝试,结果发现 vagrant 中的 service apache2 stopstart 没有按预期工作。在 /etc/apache2/envvars 中设置 PATH 变量后,尝试通过重新加载 vagrant 来重新加载 apache:vagrant reload