Roadblock(s) in getting started with Node.js - Permission denied

I tried setting up a do-nothing Node app, and it failed.

I developed some Node.js code offline in containers. I now want to try deploying it on DreamHost. I am doing it incrementally, adding features one by one. Starting with “Hello World” and going from there.

I set up a new subdomain and enabled Passenger. I was able to serve up an index.html file. I followed https://help.dreamhost.com/hc/en-us/articles/360029083351-Installing-a-custom-version-of-NVM-and-Node-js and installed Node and nvm (using the versions recommended in that artcle). I then installed a few packages I plan to use (most notably Express, the rest won’t come into play until later).

With just a Hello World app, that failed. The error message is below. But, I checked all the relevant files and they all have global read and execute permissions. I’m wondering if it is something else. I tried multiple Hello World styles for app.js, copied directly from different tutorials, none of which worked. My more complex code also does not work, but that is the next step.

What am I missing? I followed the directions exactly. What other landmines do I have to look forward to? I really don’t want to spend time wrestling with infrastructure, I want it to “just work”, ideally.

An error occurred while starting the web application. It exited before signalling successful startup back to Phusion Passenger. Please read this article for more information about this problem.

Raw process output:

*** ERROR ***: Cannot execute /home/<user name>/.nvm/versions/node/v12.16.3: Permission denied (13)

/.nvm/versions/node/v12.18.0/bin/node

One thing to check is that all directories in the path and the node binary itself are
chmod 755 – (rwxr-xr-x)

2 Likes

Thanks. But, as I said in my original post: “I checked all the relevant files and they all have global read and execute permissions.” So it’s not that .Good suggestion to start with, as it seems obvious.

“Global read and execute permissions” is longhand for 0777 and there are security measures implemented on webservers that check (and at times refuse to run) user-supplied scripts and binaries that have paths and files set too liberally. 0755 should be considered the maximum safe mode and by ensuring safe limits we can exclude the often invisible hand of security getting in the way.

Moving forward, if we take it on faith that Passenger isn’t being tripped up by general permission settings or premature failure in the app.js itself then the next step is to reset the current custom node environment.

$ setfattr -n user.pax.flags -v "mr" $NVM_DIR/nvm.sh
$ nvm install v12.18.0
$ setfattr -n user.pax.flags -v "mr" $(find $NVM_DIR -type f -iname "node" -o -iname "npm" -o -iname "npx")
$ nvm use v12.18.0

Edit .htaccess file in your application web directory:
PassengerNodejs /home/<username>/.nvm/versions/node/v12.18.0/bin/node

Create and update the timestamp of a Passenger restart file:
$ mkdir -p ~/<webdirectory>/tmp
$ touch ~/<webdirectory>/tmp/restart.txt

It seems to work now. Thanks.

Note: 755 is read and execute for everyone. 777 is read, write, and execute for everyone. I made no changes in this regard since I wrote my initial message.

I tried the .htaccess suggestion the other day, based on intuition. It didn’t seem to help, as it was still not working as of my last test.

Creating the tmp/restart.txt file seems to be the thing that worked now. I don’t know why though. What is the significance of that file?

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.