Skip to main content

Plesk 12.5 and Node.js

nodeJS

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.

21 thoughts

  1. dirk -

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

    Reply

    Alexei Yuzhakov -

    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

    Reply

  2. Sniker -

    Can’t deploy Node.js app…crap

    Reply

    Alexei Yuzhakov -

    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?

    Reply

  3. Alexei Yuzhakov -

    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.

    Reply

  4. bbb -

    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…

    Reply

    Alexei Yuzhakov -

    Disable SElinux by calling:
    setenforce 0

    And everything will be ok 🙂

    Reply

  5. Theraw -

    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 ?!

    Reply

    Alexei Yuzhakov -

    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.

    Reply

  6. AmaZili -

    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.

    Reply

  7. Eduard Duluman -

    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.

    Reply

    Alexei Yuzhakov -

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

    Reply

  8. Madalin Ignisca -

    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?

    Reply

    Alexei Yuzhakov -

    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.

    Reply

  9. Dairren -

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

    Reply

  10. Momosh -

    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?

    Reply

  11. Alexei Yuzhakov -

    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).

    Reply

    Momosh -

    Thanks Alexei, PassengerStartupFile option works like a charm 🙂

    Reply

  12. Joshua Tam -

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

    Reply

  13. Touins -

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

    You do not have permission to access this document.

    Reply

    Alexei Yuzhakov -

    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).

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

74 Shares
Tweet6
Share57
Share10
Buffer
Reddit
+11