Rails + Passenger: Can't execute shell commands - ruby-on-rails

I've setup Apache + Rails + Passenger and the app loads correctly (for the most part). The application uses Tesseract and GS to convert PDFs into images and then take their text and insert it into the database.
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:
App 14107 stderr: sh: tesseract: command not found
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.
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
The user that passenger runs as can also run the command 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?
Thanks

Thanks to shellter for pointing me in the right direction. This is what fixed the issue for me:
Apache couldn't call tesseract, so I had to add it to its path. Based on this answer (How to add path to Apache), I went to /etc/sysconfig/httpd (this is CentOS specific) and added the line:
export PATH=<the path>
To get the path, I just ran this in the console:
env
And took the output for the PATH.

Related

How does one make sure that their rails environment on one machine is the same as another?

I have three macs. I have a rails app, that I can run on two of them. On the third, I can create a new rails app and it works fine and some of my other rails apps from the other machines work fine, however the one that I need to have work on the one machine always gives me a message about not being able to find an image:
/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib
Reason: image not found - /Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
I have followed suggestions about installing the mysql2 bundle using:
gem install mysql2 -v '0.5.3' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
then bundle install, and it says all is fine. Yet 'rails s' produces that unable to find image message.
I use rbenv to manage versions and on all machines ruby is 2.6.3 and rails is 5.2.4.
What other aspects of the configuration of the app do I need to check to make sure they are the same? I have a script called 'laptop' that I obtained using:
cd ~
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/mac
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/Brewfile
/usr/bin/env bash mac 2>&1 | tee ~/laptop.log
I run this on each machine when I am setting up to install or run a rails app. On the problem machine I do get messages like:
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python#2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
during the laptop run, but at the end it says all modules were installed correctly. I have a feeling that's not really true and may be part of the problem. If so, what is causing this? I'm running OS X 10.14.6 on the machine in question.
I also notice that libssl.1.0.0.dylib is NOT present at the specified location. How do I install this and moreover, how to I make sure that all of these pieces are properly coordinated?
Found it finally! Thank you:
https://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html
I had looked at a lot of these and tried the making a soft link to no effect, but this was the first time I found this one!:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
worked!

WickedPDF not working in production server

I am using wicked_pdf gem, it works fine in local machine, but in server its not working.
I have checked the process of wkhtmltopdf, It tries to run follwoing command
/usr/local/bin/wkhtmltopdf -q file:///tmp/wicked_pdf20150609-25535-im12hx.html tmp/wicked_pdf_xxx.pdf
When I run this command in server, I get this exception
Unable to load library icui18n "Cannot load library icui18n: (icui18n: cannot open shared object file: No such file or directory)"
I installed libicu48 package from here https://launchpad.net/ubuntu/trusty/amd64/libicu48/4.8.1.1-13+nmu1ubuntu1
After this following command takes long time
/usr/local/bin/wkhtmltopdf -q file:///tmp/wicked_pdf20150609-25535-im12hx.html tmp/wicked_pdf_xxx.pdf
I have removed "bootstrap.css" from PDF generation. Now its working fine

rails s command does not run from ssh

I am using Putty to connect to my localhost, and I don't have any problems apparently, however, when I run command rails s to start my rails 4.0.0 application from Putty, it gives me this message:
jose#jose-laptop:~/rails/dedicated-agenda$ rails s
The program 'rails' can be found in the following packages:
ruby-railties-3.2
ruby-railties-4.0
Try: sudo apt-get install
I don't get that message from the terminal though, the application starts running just fine.
I had to reinstall ubuntu so I upgraded to ubuntu 14.04 just in case you need to know.
I don't know if I am missing something in my ssh settings or how could I use rails s from Putty.
Thanks in advance.
Your PATH environment variable is set differently when you are executing programs in an interactive shell and by ssh(using putty).
Use absolute path of the program to not depend on the PATH variable.
You can also set the right PATH variable at ~/.profile file and load the updated variables using the command source ~/.profile.
Now, you should be able to run the command.
You can use the command
>which rails
to see where rails is installed on your working session.
Then you need to make sure that is in your path when you ssh in.
If you are ssh'ing in as a different use then that user may not have permission to see the rails executable.

rubys> cd command not working in command line

I'm just getting into ruby and am trying to execute a walkthrough from Sam Ruby's Agile web development.
I've created a directory using mkdir work
Next i'm instructed to open a terminal and type rubys> cd work
The error I'm getting reads:
No command 'rubys' found, did you mean:
Command 'ruby' from package 'ruby' (main)
rubys: command not found
Can anyone inform me of what I'm doing wrong?
I've also tried changing from ~ to the work directory before entering my command.
In this book, rubys> is a command prompt, much like you have C:\> in the Windows terminal.
Ignore that first bit and everything should start working.
I guess you're doing it wrong.
mkdir work
creates a directory called "work". It has nothing to do with Ruby.
cd work
will then change into that directory. Forget about the rubys>.

Bash Command which Rails does Not Find

Passenger says:
Ruby on Rails application could not be started
...
Command 'exiftool' not found (MiniExiftool::Error)
When I login with ssh and I type exiftool in any directory the command works properly.
I have the follwing line in both .bash_profile and .bashrc
export PATH=$PATH:$HOME/bin
Is it possible that Rails (MiniExiftool plugin) does not recognize that bash command? How can I fix this behaviour?
The PATH for the user your server runs as does not include the directory that exiftool is in. You can either add it to that user's path, or you can refer to exiftool using its full path. I'd recommend this second approach for reasons of security. There are a number of attacks that involve putting trojan horses in a user's path ahead of the directories where the real binaries live.

Resources