Node.js App setup guide

  1. From the cPanel SOFTWARE section, click the Setup Node.js App icon.
  1. Click the CREATE APPLICATION button. Complete the fields.
    In our example, we will be installing the application in /home/youraccount/myghostblog, and be serving it from http://krystaldemo.co.uk/blog, using Node.js version 10.
  1. Installation of the Ghost blog software must be done from the command line. SSH into your account, and enter this command (replacing your cPanel username and Application root as required)
    This will enter you into a virtual shell environment setup for the Node.js version your application uses. Entering the pwd command should show that you are now in the application's root directory.
    $ source /home/krystald/nodevenv/myghostblog/10/bin/activate && cd /home/krystald/myghostblog
    [myghostblog (10)] [[email protected] myghostblog]$ pwd
    /home/krystald/myghostblog
  2. Next, install the ghost-cli, a command line interface for managing ghost installations.
    $ npm install [email protected] -g
    /home/krystald/nodevenv/myghostblog/10/lib/bin/ghost -> /home/krystald/nodevenv/myghostblog/10/lib/lib/node_modules/ghost-cli/bin/ghost
    + [email protected]
    added 363 packages from 191 contributors in 27.297s
    The ghost binary (which is actually the ghost-cli binary) is installed. We will need the your version of the path highlighted above in a while, so make a note of it.
  3. Now, we must remove all files from the application root directory (/home/krystald/myghostblog) so it's empty again (otherwise ghost won't install in the next step). BE VERY CAREFUL to make sure you are in the correct directory - enter the pwd command again to make sure you are in the Application root directory before issuing the rm -rf * command
    $ pwd
    /home/krystald/myghostblog
    $ rm -rf *
  4. Now we are ready to install the ghost blog software itself. We don't want it to try and install nginx or MySQL, so we use the --no-setup option along with the ghost cli command we highlighted above.
    $ /home/krystald/nodevenv/myghostblog/10/lib/bin/ghost install local --no-setup
    ✔ Checking system Node.js version
    ✔ Checking current folder permissions
    ✔ Checking memory availability
    ✔ Checking for latest Ghost version
    ✔ Setting up install directory
    ✔ Downloading and installing Ghost v2.31.1
    ✔ Finishing install process
  5. This process can take a minute or two, so please be patient. Once installed, there are a few things we need to do in order to get Ghost running. Passenger, the software which allows your application to be served via LiteSpeed, requires the public directory exist in the Application root, so run the following command:
    $ mkdir public
    $ chmod 755 public
  6. Your Application root should now contain the following file/directory structure
    [myghostblog (10)] [[email protected]er myghostblog]$ ls -la
    total 8
    drwxr-xr-x 5 krystald krystald 103 Oct 3 08:57 .
    drwx--x--x 24 krystald krystald 4096 Oct 3 08:53 ..
    drwxrwxr-x 8 krystald krystald 108 Oct 3 08:51 content
    lrwxrwxrwx 1 krystald krystald 42 Oct 3 08:53 current -> /home/krystald/myghostblog/versions/2.31.1
    -rw-rw-r-- 1 krystald krystald 60 Oct 3 08:53 .ghost-cli
    drwxr-xr-x 2 krystald krystald 10 Oct 3 08:57 public
    drwxrwxr-x 3 krystald krystald 27 Oct 3 08:51 versions
  7. Because ghost-cli installs the app into [Application root]/current, we need to create the default app.js file expected by Passenger and tell it where to find the Ghost application bootstrap file. Start Nano from the command line with:
    $ nano app.js
    once in nano, type the following as the first and only line
    const app = require('./current/index.js');
    Then, save the file by pressing Ctrl-x then capital Y to confirm, and hit enter to confirm the filename.
    We must setup a MySQL database and MySQL user using the tools within cPanel. This is covered in our separate guide on creating MySQL Databases and Users - link opens in a new window.
  8. The next step requires considerable editing, so you may want to edit the file locally using an editor of your choosing. Use your details for the paths as well as the MySQL database name, database user and password.
    Modify ./current/core/server/config/env/config.production.json as follows:
    {
    "server": {
    "host": "127.0.0.1",
    "port": 2368
    },
    "url": "http://krystaldemo.co.uk/blog",
    "database": {
    "client": "mysql",
    "connection": {
    "host": "localhost",
    "port": 3306,
    "user": "krystald_ghostdbuser",
    "password": "yourdbpassword",
    "database": "krystald_ghostdb"
    }
    },
    "mail": {
    "transport" : "Direct",
    "from": "[email protected]"
    },
    "paths": {
    "contentPath": "content/"
    },
    "logging": {
    "level": "info",
    "rotation": {
    "enabled": true
    },
    "transports": ["file", "stdout"]
    }
    }
  9. Once you have modified the above file and saved it, go back into the cPanel Node.js management screen, and restart the application using the Actions controls on the right hand side.
  10. If all is well, you should now be able to browse to your website at the URL you set the application up on, in our case, http://krystaldemo.co.uk
  11. It may take a few moments for the application to start, during which time you may see the following message.
    This is normal. After a few moments you should be able to refresh the page and see your blog.
  12. To setup our blog, browse to http://krystaldemo.co.uk/blog/ghost/#/setup (your URL will differ, depending on the URL you setup for the Application) - here you can setup your own admin login:
    Once you have setup your admin area, to get back to the admin login in future, simply append ghost to the end of your blog URL e.g. http://krystaldemo.co.uk/blog/ghost


How did we do?


Powered by HelpDocs
© Krystal Hosting Ltd 2003–2019