douya1061 2018-04-08 22:02
浏览 188

从PHP中运行Rscript:无法加载共享库

I am trying to run R code from within PHP. I am using RHEL 7.4.

However, because Apache runs as a different user than installed the R packages, it cannot load packages:

My PHP code has this line:

echo shell_exec("(Rscript -e 'library(lme4, lib.loc = \"/var/www/R/lib\")')2>&1");

which produces this error in the browser:

Error: package or namespace load failed for 'lme4' in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/var/www/R/lib/Rcpp/libs/Rcpp.so':
  /var/www/R/lib/Rcpp/libs/Rcpp.so: failed to map segment from shared object: Permission denied
Execution halted

The file /var/www/R/lib/Rcpp/libs/Rcpp.so has permissions 775, so I don't think the permissions are actually the problem.

How can I tell Apache / PHP where to look for the shared libraries?

The server is not public-facing, so I would take any solution from properly accessing the shared library, to giving user apache sudo access with NOPASSWD to run as my user (or something similarly reckless, since that didn't actually work...).

Thank you!

  • 写回答

1条回答 默认 最新

  • duanchu0031 2018-04-09 17:35
    关注

    This appears due in part to an SELinux setting in Red Hat. I'm not entirely sure whether this is Red Hat-centric, or specific to the configuration at my university (who installed Red Hat in the first place).

    Originally:

    $ getenforce
    Enforcing
    

    Fix:

    $ sudo setenforce 0
    $ getenforce
    Permissive
    

    Persistent fix: modify /etc/selinux/config to have the line

    SELINUX=Permissive
    

    Credit to this StackOverflow thread.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致