Cannot get Ruby on Rails application (Redmine) to run after installation

Operating System & Version
CENTOS 7.8
cPanel & WHM Version
86.0.21

benryves

Member
Jun 11, 2020
5
2
3
United Kingdom
cPanel Access Level
Root Administrator
Hello!

I've set up a blank installation of Redmine using the instructions at this URL: https://documentation.cpanel.net/display/CKB/How+to+Install+a+Redmine+Web+Application

The installation on the command-line seemed to go without a hitch, no error messages were reported, the database migration went well, the load of default data all ran without any error messages etc. I did all of it logged in as the "redmine" user with the exception of the parts that needed to be carried out as "root".

The application is installed in a directory "redmine" for the user "redmine", so the path is /home/redmine/redmine

After installation I went to cPanel's Application Manager and set it up as follows:

Application Name:
Redmine

Deployment Domain:
redmine.example.com

Base Application URL:
redmine.example.com/

Application Path:
/redmine

Deployment Environment:
Production

Now, if I restart Apache and point my browser at redmine.example.com/ I just get the web server's "Proudly powered by LiteSpeed Web Server" message and not the Redmine application. I tried changing the Base Application URL to redmine.example.com/test (in case it absolutely needed to be installed under a specific path like that) but attempting to access it produced a 404 instead.

The Application Path seems to be correct, too, if I put in the full /home/redmine/redmine path it corrects it to /redmine and if I change it to something deliberately wrong the "Ensure dependencies" button disappears from the application manager list.

The only other indication I get of something being amiss is if I click "Ensure dependencies" in the Application Manager I get an error:

gem: The process failed. Run the following command from the command line:
cd /home/redmine/redmine && scl enable ea-ruby24 'bundle install'

Now, I can run that command as the "redmine" user and it works (and I had already run it as part of the installation), so I'm not sure what the issue is there. I do note that ruby and gem are not available to the root user, is that normal/OK?

Thanks in advance for any pointers in the right direction!
 

benryves

Member
Jun 11, 2020
5
2
3
United Kingdom
cPanel Access Level
Root Administrator
LiteSpeed seems to be the culprit in all this, I found an option in WHM to switch between LiteSpeed and Apache and after switching to Apache Redmine suddenly started working beautifully.

According to Ruby LSAPI Overview - LiteSpeed Technologies LiteSpeed should be able to run Ruby applications however I can't access its control panel (attempting to launch it navigates to :7080 which times out) so haven't figured that part of the puzzle out yet.
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,274
1,291
313
Houston
I'm glad at least you got the issued identified. When attempting to access their panel do you have the port open in your firewall? It's not something that's normally opened.
 

benryves

Member
Jun 11, 2020
5
2
3
United Kingdom
cPanel Access Level
Root Administrator
I'm glad at least you got the issued identified. When attempting to access their panel do you have the port open in your firewall? It's not something that's normally opened.
Hi Lauren,

Thank you for getting back to me, our hosting provider opened port 7080 and sent over the admin password for LiteSpeed so I was able to log in to its admin panel but was still unable to get the application to run (it still produced a 404 error) so I gave up and reverted to Apache. It was then pointed out that we were paying extra for LiteSpeed so I needed to get it working... :)

In case it helps, this is how I got it working (there seems to be a lot of outdated or misleading information out there, so hopefully I'm not adding to that pile...)

After restarting the LiteSpeed server it would display a message about the Ruby Path being undefined, so I first determined the correct Ruby path from the terminal:
Code:
[email protected] [~]# which ruby
/opt/cpanel/ea-ruby24/root/usr/bin/ruby
I then copied /opt/cpanel/ea-ruby24/root/usr/bin/ruby into the "Ruby Path" field in Server→App Server→Rack/Rails Default Settings of the LiteSpeed admin panel and restarted the server. After this attempting to access the Ruby application produced a 503 error instead of a 404 error, which seemed to be a good indication that at least it was trying (albeit failing) to run the application. I looked in the Apache error log:
Code:
[email protected] [~]# tail /usr/local/apache/logs/stderr.log
2020-06-23 00:46:02.525 [STDERR] /opt/cpanel/ea-ruby24/root/usr/bin/ruby: error while loading shared libraries: libruby.so.2.4: cannot open shared object file: No such file or directory
2020-06-23 00:46:03.036 [STDERR] /opt/cpanel/ea-ruby24/root/usr/bin/ruby: error while loading shared libraries: libruby.so.2.4: cannot open shared object file: No such file or directory
2020-06-23 00:46:04.039 [STDERR] /opt/cpanel/ea-ruby24/root/usr/bin/ruby: error while loading shared libraries: libruby.so.2.4: cannot open shared object file: No such file or directory
As far as I can see this can be caused by a missing/incorrect LD_LIBRARY_PATH environment variable, so I found the value from the terminal:
Code:
[email protected] [~]# echo $LD_LIBRARY_PATH
/opt/cpanel/ea-ruby24/root/usr/bin/../local/bin:/opt/cpanel/ea-ruby24/root/usr/lib64:/opt/cpanel/ea-openssl/lib64
...and then appended this to the "Environment" field under Server→App Server→Rack/Rails Default Settings in the LiteSpeed settings, which in my case made it this:
Code:
LSAPI_MAX_REQS=1000
LSAPI_MAX_IDLE=60
LD_LIBRARY_PATH=/opt/cpanel/ea-ruby24/root/usr/bin/../local/bin:/opt/cpanel/ea-ruby24/root/usr/lib64:/opt/cpanel/ea-openssl/lib64
After restarting the server the Ruby on Rails application could be accessed and there were no more errors appearing in the logs, so fingers crossed this is what it took! There is information out there for LiteSpeed about configuring Virtual Hosts or Virtual Host Templates to determine the appropriate application paths which I didn't touch so I can only assume it's pulling the requisite information from the application configuration set up in cPanel. Other places mention a file called ~/.ls_rails_config that needs to be set up to configure the application, I did briefly have this set up too but it didn't seem to do anything and after deleting the file (and restarting the server several times) the application is still running fine so I don't think that's necessary either.

As an aside, when setting up the cron job in cPanel to handle incoming emails to the application I ran into similar path issues but was able to resolve that by configuring the cron job to run with bash:
Code:
/bin/bash -l -c 'cd ~/redmine && rake --silent redmine:email:receive_imap RAILS_ENV="production" host=<host> username=<username> password=<password>'
Hopefully this might help someone in future if they're also having difficulty with Ruby on Rails and LiteSpeed. (At least until a new version comes out that completely changes how everything is set up, of course)!
 
  • Like
Reactions: cPanelLauren

benryves

Member
Jun 11, 2020
5
2
3
United Kingdom
cPanel Access Level
Root Administrator
Sorry to bump my own thread after so long but in case this helps anyone else, I recently upgraded Redmine from 4.1.1 to 4.2.4 on the server (not touching any of the server configuration directly, just going through the usual Redmine installation/upgrade procedure) and it worked fine for three days and then started returning HTTP 503 errors from LiteSpeed. The site ran fine when switching the web server to Apache, but switching to LiteSpeed brought back those HTTP 503 errors. Rebooting the server or removing and reconfiguring the application didn't seem to help. The errors in the Apache log were like the following:

Code:
2022-03-09 01:19:48.178697 [INFO] [7027] [T0] [127.0.0.1:59780:HTTP2-17#APVH_redmine.example.com:443] connection to [uds://tmp/lshttpd/APVH_redmine.example.com:443:_.sock] on request #0, confirmed, 0, associated process: 0, running: 0, error: Connection refused!
2022-03-09 01:19:48.178701 [INFO] [7027] [T0] [uds://tmp/lshttpd/APVH_redmine.example.com:443:_.sock] Connection refused, restart!
2022-03-09 01:19:48.178706 [INFO] [7027] [T0] [Rack:APVH_redmine.example.com:443:/] kill current detached process: 8200, started at: 1646788788
2022-03-09 01:19:48.178708 [INFO] [7027] [T0] [Rack:APVH_redmine.example.com:443:/] remove unix socket for detached process: /tmp/lshttpd/APVH_redmine.example.com:443:_.sock
2022-03-09 01:19:48.178750 [NOTICE] [7027] [T0] sendKillCmdToWatchdog: 'extappkill:8200:-3:1646788788'.
2022-03-09 01:19:48.178765 [NOTICE] [7027] [T0] [127.0.0.1:59780:HTTP2-17#APVH_redmine.example.com:443] Max retries has been reached, 503!
2022-03-09 01:19:48.178784 [NOTICE] [7027] [T0] [127.0.0.1:59780:HTTP2-17#APVH_redmine.example.com:443] oops! 503 Service Unavailable
According to this cPanel article "LiteSpeed doesn't function automatically with Ruby/Passenger/Python applications. Configuring applications without performing the setup script will result in a 503 error page when accessing the application URL", and the suggested fix is to run /usr/local/lsws/admin/misc/enable_ruby_python_selector.sh

I ran that script as root (it produced a few "You need to be root to perform this command" errors when run under the application's own account) but this did not help, however I mention it for completeness in case it is part of the solution. After a bit more digging I found this LiteSpeed article which mentions that "the easiest way to install Ruby LSAPI is as a gem" and "to upgrade, just reinstall Ruby LSAPI as a gem":

Code:
gem install ruby-lsapi
After running that command under the application's own account the Redmine installation instantly started working again and I've rebooted the server as a test and it's still up and running fine, so that appears to have been the incantation to get it working. Touch wood it'll run for more than three days before falling over again. :)
 
  • Like
Reactions: cPRex

benryves

Member
Jun 11, 2020
5
2
3
United Kingdom
cPanel Access Level
Root Administrator
I've just upgraded to Redmine 5.0.2 and this brought some additional challenges with it so once again I'm bumping this old thread in case it helps anyone else!

Redmine 5 requires Ruby 2.5 or later, which means the old 2.4 version of Ruby needs to be upgraded. This can be done by using EasyApache 4 in WHM, customising your list of installed packages under "Ruby via Passenger" to install Ruby 2.7 (in my case I installed the same ruby27-* packages as I previously had selected for ruby24-*).

Once you have provisioned the changes, log into the shell of the user that your application runs under. In my case I needed to update the .bashrc file to use the new Ruby 2.7 installation instead of Ruby 2.4, this was done with nano ~/.bashrc and changing

Code:
source /opt/cpanel/ea-ruby24/enable
to

Code:
source /opt/cpanel/ea-ruby27/enable
The file was then saved and I logged back out then in again to the shell. At this point I was able to install the Ruby application on the command-line normally with bundle install etc as per the Redmine installation instructions (previously doing this would produce a host of version-related error messages).

To make life a little easier for myself I then disabled LiteSpeed and tried to load the application under Apache; I got a Phusion Passenger error page and looking at the error log I could see it was still attempting to use Ruby 2.4 (and clicking on the "Ensure dependencies" button in the application manager would bring up an error with ea-ruby24 in the path). Unregistering and re-registering the application switched it to use the new Ruby 2.7 installation and Redmine reappeared and the "Ensure dependencies" button also started working again.

I then switched back to LiteSpeed, which required some additional work:

  • In the LiteSpeed WebAdmin Console, go into Configuration, App Server, and change:
    • "Ruby Path" to /opt/cpanel/ea-ruby27/root/usr/bin/ruby
    • "Environment" to include an appropriate LD_LIBRARY_PATH e.g. LD_LIBRARY_PATH=/opt/cpanel/ea-ruby27/root/usr/bin/../local/bin:/opt/cpanel/ea-ruby27/root/usr/lib64:/opt/cpanel/ea-openssl/lib64
  • In a shell as the root user edit the .bashrc to ensure the root user is using the Ruby 2.7, log out then in again, then run /usr/local/lsws/admin/misc/enable_ruby_python_selector.sh
  • In a shell as the application user run gem install ruby-lsapi in the application folder.

At this point the application should be running under LiteSpeed. The one outstanding issue I have is that rake seems unable to find bundler, as running it always produces the following error:

Code:
Gem::GemNotFoundException: Could not find 'bundler' (2.3.19) required by your /home/redmine/redmine/Gemfile.lock.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.3.19`
bundler is installed, running gem list ^bundler$ shows that 2.3.19 was installed and which rake shows that it's running from the ea-ruby27 directory so I'm not sure what's going on there. Fortunately, I found a roundabout way to run it - instead of rake <command>, using bundle exec rake <command> does the job. The cron job to process incoming email is therefore:

Code:
/bin/bash -l -c 'cd ~/redmine && bundle exec rake --silent redmine:email:receive_imap RAILS_ENV="production" host=<hostname> username=<username> password=<password>'
I am still unable to upload files larger than 10MB under LiteSpeed (Apache is unaffected), I did ask for help on the Redmine forum two years ago but never heard back so that will remain a mystery.