Plesk Node.js Setup

Plesk 12.5 and Node.js

During the last few years, Node.js has been steadily growing in popularity. On top of that, according to StackOverflow, JavaScript is today’s most popular programming language. If you are a Node.js developer, you may be curious whether it is possible to host Node.js apps on Plesk. The short answer is “yes, it’s possible”. In this article, I’ll explain how to set up the environment step by step using an Ubuntu 14.04 server with Plesk 12.5 for my demonstration. If you want, you can use other OSes or Plesk versions, but there can be the minor differences in commands and instructions.

I assume that you’ve already tried installing Node.js on the server. If not, let’s do it right now using the official instructions provided at nodejs.org:

Let’s verify the installation by checking the version of Node.js:

Output should look like this:

The next thing to do is to install an application server.  Plesk 12.5 comes with the Phusion Passenger component that you can install with just a few clicks. If you’re unsure what do we need the application server for, just take my word for it – the task will be mush simpler with it.

Ok, let’s go ahead. Log in to Plesk as the admin , go to “Tools & Settings” and click the “Updates & Upgrades” link:

Tools___Settings_-_Plesk_12_5_30

Click “Add/Remove Components” on the next screen. Expand the “Web hosting” section and mark the “Phusion Passenger server” component for installation:

Plesk_Installer

Phusion Passenger will run as a web server module, so after the installation, it will have to be enabled. Return to “Tools & Settings” and click the “Apache Web Server” link (found under “General Settings”). Here we need to enable the “passenger” module:

Apache_Web_Server_Settings_-_Plesk_12_5_30

The next step is to prepare a domain for hosting our Node.js app. We need to set up a proper document root for the domain. By default, Phusion Passenger looks for the app.js file that should be located in the parent directory of the document root. We will deploy our app to the “my-app” directory, so we need to set up the document root as “my-app/public”. Go to “Websites & Domains” for your domain and click “Hosting Settings”. Here, we need to change the document root, so it looks like this:

Hosting_Settings_for_a10-52-48-240_qa_plesk_ru_-_Plesk_12_5_30

The final step is to deploy our Node.js app. We will use a basic “Hello World” app as for this example. You can use the File Manager to create the following directory structure in the root of the webspace:

File Manager

Alternatively, log in via SSH with the webspace system user credentials (don’t forget to enable SSH access on the “Web Hosting Access” screen) and run the following commands

Then, create the my-app/app.js file with the following contents:

Let’s check the results by browsing your domain. You should see the “Hello World” text on the page. The /var/log/apache2/error.log log file should contain the “Node.js app is running…” message if everything is ok, or some error messages otherwise.

The last thing I’d like to mention is how to restart the app. Use the standard Phusion Passenger method – namely, create or “touch” a file named restart.txt in the tmp directory:

That’s it, congratulations! In no time at all, you’ve got your very own Node.js app running on a Plesk server.

About

Showing 29 comments
  • dirk
    Reply

    its not working here, looks like there is something wrong in this ..
    also no logfile apache2…

    • Alexei Yuzhakov
      Reply

      It seems that your have not an Ubuntu server, but on some other OS. In case of CentOS Apache error log file is located at /var/log/httpd/error_log

  • Sniker
    Reply

    Can’t deploy Node.js app…crap

    • Alexei Yuzhakov
      Reply

      Can you explain your problem with a little more details? Do you use Ubuntu 14.04 with Plesk 12.5 or something else? Do you see some error on the screen or at /var/log/apache2/error.log file?

  • Alexei Yuzhakov
    Reply

    In case if you see 403 error page (forbidden) it probably means that Passenger can’t detect the app automatically. We can help the app server by adding the following directive to “Additional Apache directives” (“Apache & nginx Settings” button):
    PassengerAppRoot “/var/www/vhosts/your-domain.dom/”
    Where your-domain.dom should be replaced with a name of your domain.

    • Jakob Alexander Eichler
      Reply

      I do not see a 403 page but I get 403 errors in the developer console. I followed your advice but it did not help.

  • bbb
    Reply

    THis is what i get from CentOS Plesk from AWS marketplace

    and /tmp/passenger-error-R2GRSe.html does not get created…

    i have also tested by adding these to the Additional directives for HTTP

    PassengerAppRoot /var/www/vhosts/testing.example.com/
    PassengerAppType node
    PassengerStartupFile my-app/app.js

    [ 2016-06-30 21:00:07.8849 28220/7f94cadac880 age/Wat/Main.cpp:1293 ]: Starting PassengerAgent watchdog…
    [ 2016-06-30 21:00:07.8906 28223/7f1571f16880 age/Hel/Main.cpp:957 ]: Starting PassengerAgent server…
    [ 2016-06-30 21:00:07.8907 28223/7f1571f16880 age/Hel/Main.cpp:234 ]: PassengerAgent server running in multi-application mode.
    [ 2016-06-30 21:00:07.8922 28223/7f1571f16880 age/Hel/Main.cpp:707 ]: PassengerAgent server online, PID 28223
    [ 2016-06-30 21:00:07.8961 28230/7ff213e8d880 age/Log/Main.cpp:430 ]: Starting PassengerAgent logger…
    [ 2016-06-30 21:00:07.8967 28230/7ff213e8d880 age/Log/Main.cpp:311 ]: PassengerAgent logger online, PID 28230
    [Thu Jun 30 21:00:07.898969 2016] [mpm_event:notice] [pid 28188:tid 139628521592896] AH00489: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 Phusion_Passenger/5.0.10 configured — resuming normal operations
    [Thu Jun 30 21:00:07.898995 2016] [core:notice] [pid 28188:tid 139628521592896] AH00094: Command line: ‘/usr/sbin/httpd -D FOREGROUND’
    App 28795 stdout:
    [ 2016-06-30 21:02:52.5011 28223/7f1571d7f700 App/Implementation.cpp:303 ]: Could not spawn process for application /var/www/vhosts/testing.example.com/my-app: An error occurred while starting the web application. It exited before signalling successful startup back to Phusion Passenger.
    Error ID: ebfe7ad1
    Error details saved to: /tmp/passenger-error-R2GRSe.html
    Message from application: 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:
    (empty)

    [ 2016-06-30 21:02:52.5090 28223/7f155ffff700 age/Hel/Req/CheckoutSession.cpp:252 ]: [Client 1-1] Cannot checkout session because a spawning error occurred. The identifier of the error is ebfe7ad1. Please see earlier logs for details about the error.
    [Thu Jun 30 21:08:06.640590 2016] [mpm_event:notice] [pid 28188:tid 139628521592896] AH00492: caught SIGWINCH, shutting down gracefully

    [ 2016-06-30 21:08:07.6694 28223/7f155ffff700 age/Hel/Main.cpp:507 ]: Signal received. Gracefully shutting down… (send signal 2 more time(s) to force shutdown)
    [ 2016-06-30 21:08:07.6695 28223/7f1571f16880 age/Hel/Main.cpp:876 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected…

    • Alexei Yuzhakov
      Reply

      Disable SElinux by calling:
      setenforce 0

      And everything will be ok 🙂

  • Theraw
    Reply

    can’t understand how this work.
    anyway at CentOS 7 With plesk onyx 17.0.14 isn’t working!
    At logs can’t find nothing.
    Might be any button example node app.js ?!

    • Alexei Yuzhakov
      Reply

      Make sure you have disabled SELinux. Make sure nodejs is installed.
      Check /var/log/httpd/error_log file for errors. Provide output of the error if present.

      • Jakob Alexander Eichler
        Reply

        I am having the same issue.

        Maybe this helps….

        [Thu May 04 20:00:26.154360 2017] [passenger:error] [pid 3914:tid 140611937753216] *** Passenger could not be initialized because of this error: Unable to start Phusion Passenger: Support binary PassengerAgent not found (tried: /usr/lib64/passenger/locations.ini/buildout/support-binaries/PassengerAgent and /root/.passenger/support-binaries/5.0.30/PassengerAgent). There may be different causes for this:nn – Your ‘PassengerRoot’ setting is set to the wrong value. Please see https://www.phusionpassenger.com/library/config/apache/reference/#passengerroot to learn how to fix the value.n – The PassengerAgent binary is not compiled. Please run this command to compile it: /usr/lib64/passenger/locations.ini/bin/passenger-config compile-agentn – Your Passenger installation is broken or incomplete. Please reinstall Passenger.

        But I do not know if it is related.

        • Jakob Alexander Eichler
          Reply

          SELinux is disabled

        • Jakob Alexander Eichler
          Reply

          The file it is looking for can be found in /usr/lib64/passenger/support-binaries/ but if I set a symlink from where it looks at to this file, I run into the next error:
          Error: Cannot find module '/usr/lib64/passenger/locations.ini/src/helper-scripts/node-loader.js'
          at Function.Module._resolveFilename (module.js:470:15)
          at Function.Module._load (module.js:418:25)
          at Module.runMain (module.js:605:10)
          at run (bootstrap_node.js:420:7)
          at startup (bootstrap_node.js:139:9)
          at bootstrap_node.js:535:3

      • Jakob Alexander Eichler
        Reply

        The issue appeared with an update to plesk 17.01.

        You must uninstall the node js module and the passenger module after it in the plesk configuration as explained above, and than reinstall it. That solves the problem.

  • AmaZili
    Reply

    On centos 7 with onyx 17.0.14 it does not work as explained.

    The webroot is httpdocs as usual, create the my-app, my-app/public and my-app/tmp under there and it works properly.

    put everything there in due place and you will notice it working fine.

  • Eduard Duluman
    Reply

    Everything works fine, http://frisk.duluman.ro , the only problem is I have no idea how to deal with sockets. http://frisk.duluman.ro/a.html ( throws 400 Bad Request ) upon Switching Protocols. Same code, same node app, just pure vps with nodejs on it and no plesk, http://frisk.duluman.ro/b.html , works like a charm.

    Any idea ?

    Also posted here: https://talk.plesk.com/threads/phusion-passenger-websockets-handshake-issue.338945/

    Will do another test with the JXCore extension, maybe that one works better.

    • Alexei Yuzhakov
      Reply

      JXCore project is dead.
      As far as I can see the solution of your problem is found (see forum thread).

  • Madalin Ignisca
    Reply

    What happens to a Nodejs app when a change is triggered in Plesk (like adding a new subdomain or creating a new client/subscription)?

    Is the app restarted (default free passenger behaviour if is configured through Nginx/Apache) or it keeps running (separate passenger process and proxying requests using Nginx)?

    If first option, should paid version of passenger be used to make user that Nodejs/Ruby apps are never restarted because of other changes requiring to restart Apache/Nginx?

    How is this going to work in Plesk 17, as in 17.0.15 we can see that handling Ruby and Nodejs is now mentioned as supported?

    • Alexei Yuzhakov
      Reply

      Since Plesk Onyx (17.x) one can use Ruby and Node.js extensions. These extensions provide an easy way to manage the corresponding types of apps. No need to install or configure something using SSH.
      Plesk uses Passenger as a module (not as a standalone server). Ruby and Node.js extensions have convenient buttons to restart the app.

  • Dairren
    Reply

    As a beginner Its not easy to manage in one place, is there a recommendation to separate node js?

  • Momosh
    Reply

    Great tutorial and all, but I’ve been really scratching my head what is the correct way to change the folder structure with this setup?

    I don’t want my Passenger entry point to be app.js, so how can I change this with Plesk?

  • Alexei Yuzhakov
    Reply

    Plesk Onyx using Node.js extension provides an ability to change the entry point to something different than app.js. Go to Websites & Domains -> Node.js and check “Application Startup File” setting (click on “app.js” link). There will be a popup window allowing to change the entry point.
    In previous version of Plesk you can change the entry point via additional nginx/Apache directives (passenger_startup_file for nginx or PassengerStartupFile for Apache).

    • Momosh
      Reply

      Thanks Alexei, PassengerStartupFile option works like a charm 🙂

  • Joshua Tam
    Reply

    You will need to uncheck “Smart static files processing” in “Apache & nginx Settings” in order to run node.js at the domain root

  • Touins
    Reply

    Hello , i followed all steps but i got at the final
    Forbidden

    You do not have permission to access this document.

    • Alexei Yuzhakov
      Reply

      Try to read all the comments, similar issues were discussed already. It’s also important to know which version of Plesk do you use. Try to use Plesk Onyx, Node.js app setup is more simple with it (using Node.js support extension).

  • david
    Reply

    One example for https, please

  • kobelka
    Reply

    Hi,
    I also have problems with one app and node.js.
    The app (openhab-cloud) is starting but when I do a POST action in the from of the app I get an forbidden.

    In the log files I find this:
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js-plugin/hoverdir/jquery.hoverdir.js HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 5.69 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js-plugin/pretty-photo/js/jquery.prettyPhoto.js HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 24.7 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js-plugin/rs-plugin/js/jquery.themepunch.plugins.min.js HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 15.9 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js-plugin/rs-plugin/js/jquery.themepunch.revolution.min.js HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 52.2 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js/custom.js HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 33.0 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js/Chart.min.js HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 50.9 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /setTimezone?tz=Europe/Berlin HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 12 SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:39 Access 194.127.26.77 200 GET /js-plugin/jquery-cookie/jquery.cookie.js?_=1489595859849 HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 1.86 K SSL/TLS-Zugriff für nginx
    2017-03-15 17:37:40 Error 194.127.26.77 403 POST /register HTTP/1.1 https://opencloud.kobelka.de/ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 10 SSL/TLS-Zugriff für nginx

    Can anybody help me ?

Leave a Comment

Start typing and press Enter to search