10

I'm deploying a rails app using Apache and Phusion Passenger I already deployed apps using this stack but now i'm using NVM to install node but when I try to load the site shows an error, looking on logs shows this error:

Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

On this server I didn't installed nodejs from OS repos, and looking on the passenger documentation shows something about passenger_nodejs but this is from nginx.

This is my conf from apache:

ServerName yourserver.com

# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /var/www/myproj/public

PassengerRuby /home/appuser/.rvm/gems/ruby-2.3.0/wrappers/ruby
PassengerNodejs /home/appuser/.nvm/versions/node/v6.9.2/bin/node


# Relax Apache security settings
<Directory /var/www/myproj/public>
  Allow from all
  Options -MultiViews
  # Uncomment this if you're on Apache >= 2.4:
  Require all granted
</Directory>

and keep showing that error

Installing nodejs from OS repos fix the message and the app works but is because it's using the node version from OS but I want to use the NVM version.

MaxJRB
  • 612
  • 2
  • 7
  • 16
  • 1
    `passenger_nodejs` do nothing in `Ubuntu 18.04.5` , `nginx/1.14.0` and `Phusion Passenger 6.0.6`. I have to use @krsyoung solution. – inye Nov 10 '20 at 15:32

3 Answers3

20

I have the same problem and don't have a good solution but I did find I was able to get around my problem by creating a symbolic link like:

ln -sf /home/deploy/.nvm/versions/node/v6.10.1/bin/node /usr/local/bin/node

Doesn't work very well if there are multiple deployments on the same server but I also couldn't find a way to "properly" use NVM with Passenger / Rails.

krsyoung
  • 1,171
  • 1
  • 12
  • 24
1

One other way to do this that doesn't require writing to /usr/local/bin is to use the https://www.phusionpassenger.com/library/config/apache/reference/#passengernodejs PassengerNodeJs directive. This also works if you have other apps on the server using a different version of node.

Brian Minton
  • 3,377
  • 3
  • 35
  • 41
0

Small bash script to simplify life, it remains a workaround... As in krsyoung answer but at least the multiple versions work

#!/bin/bash
source $NVM_DIR/nvm.sh
nvm install $1
IFS='/' read -r -a result <<< "$NVM_BIN"
ln -sf $NVM_DIR/versions/node/${result[-2]}/bin/node /usr/local/bin/node${result[-2]}
echo "You can access your node using the command \"node${result[-2]}\""

When running the script followed by the fully version or not will make a symbolic link

Example of use

./deploy.sh 18

Will take the latest version18.x.x

or

./deploy.sh 18.14.2

Will take precisely this version...

The node will then be accessible by typing

nodev18.14.2

or

/usr/local/bin/nodev18.14.2
WaRtrO
  • 1
  • 1