}
In order to deploy a NodeJS application we need to enable NodeJS using cPanel, please review the following article: Enabling NodeJS in cPanel
In this example, we will cover the basics and teach you how to deploy Ghost CMS as an example.
For those who are experienced deploying NodeJS applications, it worth mentioning that the web server is configured with Phusion Passenger. The NodeJS Selector basically setups all the basics for you:
Look at https://docs.ghost.org/faq/node-versions/ and check the recommended version. At the time of writing this guide, the recommended Node version is 10.
Let's go ahead and setup the environment:
After we press “CREATE” the selector will create the application and provide us the command to activate NodeJS:
For this application, we will set the mode as "Production". Select Production and click SAVE.
The startup file could be any name, in this case we use "index.js" because that's the index file of GhostCMS.
a) Login via SSH to your account and execute the virtual environment command:
nodejstest@ ~ $ source /home/nodejstest/nodevenv/my_apps/ghost/10/bin/activate && cd /home/nodejstest/my_apps/ghost
[my_apps/ghost (10)] nodejs@ ~/my_apps/ghost $
b) Let's download GhostCMS in the same folder:
wget https://ghost.org/zip/ghost-latest.zip
unzip ghost-latest.zip
c) Let's remove default passenger file and folder:
rm -rf public
rm -f app.js
d) Install all packages for production
npm install --production
This command will read the file package.json and install all modules required for production. The package.json is like composer.json with Composer or Gemfile for Ruby.
e) Setup a new MySQL database and MySQL user and edit the file ./core/server/config/env/config.production.json
This is an example:
{ "database": { "client": "mysql", "connection": { "host" : "127.0.0.1", "user" : "nodejstest_ghostusr", "password" : "my_password", "database" : "nodejstest_ghostdb" } }, "paths": { "contentPath": "content/" }, "logging": { "level": "info", "rotation": { "enabled": true }, "transports": ["file", "stdout"] } }
f) Edit the file ./core/server/config/defaults.json and change the following with your domain name:
{ "url": "http://nodejs.mydomain.com", "server": { "host": "nodejs.mydomain.com", "port": 80 },
g) Go back to cPanel and click on Restart
It should work fine, it will display a message with a 503 error code. Click on "Return to home page" and that's all.
Powered by WHMCompleteSolution