简体   繁体   English

Rails + Passenger:无法执行Shell命令

[英]Rails + Passenger: Can't execute shell commands

I've setup Apache + Rails + Passenger and the app loads correctly (for the most part). 我已经设置了Apache + Rails + Passenger,并且应用程序正确加载(大部分情况下)。 The application uses Tesseract and GS to convert PDFs into images and then take their text and insert it into the database. 该应用程序使用Tesseract和GS将PDF转换为图像,然后获取其文本并将其插入数据库。

When I test the application using rails s, everything functions normally, but when I try to run some of the functions from the passenger instance, I get the following error in my apache log: 当我使用rails测试应用程序时,所有功能均正常运行,但是当我尝试从乘客实例运行某些功能时,我的apache日志中出现以下错误:

App 14107 stderr: sh: tesseract: command not found App 14107 stderr:sh:tesseract:找不到命令

The error occurs for the following code: 对于以下代码,将发生错误:

%x(gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile="page%03d".png #{self.doc.path})
%x(for f in page*.png ; do tesseract $f $f.out; done)

There is nothing in my rails production.log file that indicates any errors. 我的rails production.log文件中没有任何内容指示任何错误。

I'm running CentOS 6 and I built my tesseract using this guide: https://www.simpleservers.co.uk/clients/whmcs/knowledgebase/600/Install-Tesseract-OCR-libs-from-sources-in-Centos.html 我正在运行CentOS 6,并使用以下指南构建了tesseract: https : //www.simpleservers.co.uk/clients/whmcs/knowledgebase/600/Install-Tesseract-OCR-libs-from-sources-in-Centos html的

The user that passenger runs as can also run the command tesseract. 乘客运行的用户也可以运行命令tesseract。 I checked in its console, but for some reason, passenger can't run it. 我检查了它的控制台,但由于某种原因,乘客无法运行它。 Do I need to enable it for the apache user somehow? 我需要以某种方式为apache用户启用它吗?

Thanks 谢谢

Thanks to shellter for pointing me in the right direction. 感谢Shellter为我指出正确的方向。 This is what fixed the issue for me: 这就是为我解决问题的原因:

Apache couldn't call tesseract, so I had to add it to its path. Apache无法调用tesseract,因此我不得不将其添加到其路径中。 Based on this answer ( How to add path to Apache ), I went to /etc/sysconfig/httpd (this is CentOS specific) and added the line: 基于此答案( 如何向Apache添加路径 ),我转到了/ etc / sysconfig / httpd(这是CentOS特定的),并添加了以下行:

export PATH=<the path>

To get the path, I just ran this in the console: 为了获得路径,我只是在控制台中运行了它:

env

And took the output for the PATH. 并将输出作为PATH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM