3

我正在尝试运行 FOP(通过 php exec() 命令),当我在命令行(作为我的用户)上运行 FOP 时,它工作得非常好,但是 PHP 命令正在作为 apache 的 www-data 用户运行它和它是说没有找到 FOP。

如果我在命令行上使用 sudo -uwww-data fop 运行它,那么它也会说找不到命令。

我已经将我的 fop 路径信息与 /etc/profile 一起放入 /etc/environment 并且我已经完成了源 /etc/environment 和源 /etc/profile 但它仍然说它没有找到。

如何让 FOP 在 www-data 用户下运行?

谢谢

4

1 回答 1

0

将以下代码放入名为 like 的文件/etc/profile.d/*.sh中是实现目标的一种可怕方式,但它甚至可能有效:

#/bin/sh
if [ "`id -u`" -eq "`id -u www-data`" ]; then
   PATH="/opt/fop/latest:$PATH" ;
fi

我们测试当前用户 id 是否是www-data-user 的 id。PATH如果是这样,我们在变量前面加上/opt/fop/latest目录。每当初始化一个新的 shell 时,它应该自动运行。

这些命令将安装新脚本:

$ echo -e '#!/bin/sh\nif [ "`id -u`" -eq "`id -u www-data`" ]; then PATH="/opt/fpb/latest:$PATH"; fi' | sudo cat >/etc/profile.d/fop4www-data.sh
$ sudo chown www-data:www-data /etc/profile.d/fop4www-data.sh
$ sudo -u www-data chmod +x /etc/profile.d/fop4www-data.sh

如果命令

$ echo 'whoami; echo PATH=$PATH' | sudo -u www-data sh

从正常的 shell 运行反映了变化,你应该能够fop从你的 php 脚本中调用。

免责声明:我不喜欢 shell 编程。我几乎不知道我在做什么。请使用常识并改进代码。

于 2012-07-29T20:16:01.900 回答