Phusion Passenger: 'Initialize language runtime' and 'Load or execute application' error with nodejs app

568 Views Asked by At

My nodejs app works fine on my local machine in the dev environment, however getting it to work on the production server is a nightmare.

In a nutshell the app is starting but the content is not loading on the site. It is failing to fully initialize as the screenshot shows.

Screenshot

Anyone have any ideas about this? Even the hosting company isn't sure what is causing it and I can't find anything relevant on google so far. All I know is it is coming from Phusion Passenger...

1

There are 1 best solutions below

0
maksemm On BEST ANSWER

I will post my solution in case anyone else runs into this issue.

If you have created a nodejs app using express and have used the express generator to set the app up, you will notice the start up file is called www inside the bin folder in your projects directory. Usually it is named app.js.

Phusion Passenger looks for app.js to start the app. You need to tell Phusion Passenger to look for ./bin/www inside your config file. It will likely be different for different systems. In apache it is located here:

/etc/apache2/conf.d/userdata/std/2_4/YOUR_USERNAME/YOUR_DOMAIN/YOUR_APPNAME.conf

You need to add this startup file line:

PassengerStartupFile ./bin/www

Your config file should look something like this:

<Location "/">
    <IfModule mod_passenger.c>
        PassengerAppEnv "development"
        PassengerEnabled on
        PassengerBaseURI "/"
        PassengerAppRoot "/home/YOUR_USERNAME/YOUR_DOMAIN"
        PassengerAppGroupName "YOUR_APP_NAME"
        PassengerRuby /opt/cpanel/ea-ruby27/root/usr/libexec/passenger-ruby27
        PassengerPython /usr/bin/python
        PassengerNodejs /opt/cpanel/ea-nodejs10/bin/node
        PassengerAppType node

        PassengerStartupFile ./bin/www
        
    </IfModule>
</Location>

Then you just need to save the file, rebuild the apache http config file and restart apache.

I used the terminal inside WHM to run these two lines:

1# /usr/local/cpanel/scripts/rebuildhttpdconf

2# /usr/local/cpanel/scripts/restartsrv_httpd

Combined # /usr/local/cpanel/scripts/rebuildhttpdconf && /usr/local/cpanel/scripts/restartsrv_httpd

The instructions in this post are found here:

https://docs.cpanel.net/knowledge-base/web-services/how-to-install-a-node.js-application/