Cara install aplikasi Node.JS di hosting Cpanel

Menjalankan aplikasi NodeJS terdapat 2 cara sesuaikan dengan web server yang anda gunakan. Namun untuk pengguna Cloudlinux OS, sudah terdapat fasilitas NodeJS Selector dimana disetiap akun cPanel, kamu sudah bisa memilih versi NodeJS dan deploy aplikasi NodeJS semakin mudah. Simak semua tutorial sederhana dibawah ini


web server litespeed
https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:other-ext-apps:nodejs-setup

  1. buatlah file .htaccess pada halaman public_html anda

    Options +FollowSymLinks -Indexes

    IndexIgnore *

    DirectoryIndex

    <IfModule mod_rewrite.c>

    RewriteEngine on

    # Simple URL redirect:
    RewriteRule ^(.*)$ http://namadomain.com:65449/$1 [P]

    </IfModule>

  2. buatlah index.js dengan isi:

    note: pastikan replace namadomain.com dengan domain anda sendiri.

    var http = require('http');
    var server = http.createServer(function(req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end("hello world!\n");
    });
    server.listen(65449);

  3. start aplikasi node js anda dengan cara login ssh dan masuk ke directory public_html
    ketikkan:

    nohup node index.js &

    atau dengan membuat file cron.php yang berisikan:

    <?php

    $host = 'namadomain.com';
    $port = '65449';
    $cron = true; // Set $cron = false to Stop cron

    if(@$_SERVER['SERVER_PORT'] > 1){
    die('Not accesible via the web !');
    }

       if($cron == true){
         $checkconn = @fsockopen($host, $port, $errno, $errstr, 5);
         if(empty($checkconn)){
         exec('export HOME=/home/username; cd /home/username/public_html; npm start --production >> /home/username/nodejs.log 2>&1 &', $out, $ret); 
          echo "start app";
         }else{
          echo "already running";
         }
    }

    ?>

    lalu masuk ke menu cron jobs pada cpanel menu anda:

    4,23,34,48 * * * * php -d disable_functions="" /home/username/public_html/cron.php >> /home/username/cron.log 2>&1



pastikan jangan lupa merubah namadomain.com dan  username dengan username anda sendiri dan port degan angka yang berbeda. seperti:65480 atau 65488, dll..
setelah semua selesai , maka seharusnya dapat berjalan lancar.



web server apache

  1. buatlah file .htaccess pada halaman public_html anda

    # Start of .htaccess
    # Define AppRoot Folder
    PassengerAppRoot /home/username/public_html

    # Tell Passenger that your app is a Node.js app
    PassengerAppType node

    # Define NodeJS StartupFile 
    PassengerStartupFile index.js

    # End of .htaccess



    note: pastikan replace username dengan username account cpanel kalian.

  2. buatlah index.js dengan isi:

    var http = require('http');
    var server = http.createServer(function(req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end("hello world!\n");
    });

    maka jika anda buka domain anda akan muncul tulisan hello world.

    perlu diingat bahwa framework nodejs seperti meanJS, ExpressJS,dll juga dapat dirunning menggunakan cara diatas.
    jika ada hal-hal yang kurang jelas dapat menanyakan kepada tim support kami


 

NodeJS Selector

saat ini terdapat fitur NodeJS selector pada paket developer kami, sehingga tutorial diatas dapat digantikan dengan tutorial dibawah ini dengan lebih mudah
https://www.natanetwork.com/portal/knowledgebase/103/NEW-Tutorial-menjalankan-NodeJS-menggunakan-NodeJS-Selector-di-CPanel.html

 

 

  • NodeJs Hosting, Shared Hosting NodeJs, NodeJs Tutorial, Node Js Installation
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

Cara install Ghost untuk blogging

kami mau memberikan informasi untuk saat ini web hosting cPanel telah mendukung NodeJS + Ghostapa...

mencegah error EADDRINUSE pada waktu start Node.js app

mungkin kalian yang sedang mencoba running node js script mengalami kendala error seperti dibawah...

[NEW] Tutorial menjalankan Node.JS menggunakan NodeJS Selector di CPanel

Cloudlinux baru-baru ini merilis fitur baru yaitu NodeJS selector dimana pengguna cpanel dapat...

Cara install framework Express.js di hosting cPanel dengan mudah

Dengan menggunakan fitur nodeJS Selector pada cPanel hosting, kita dapat deploy berbagai macam...

Tutorial load ES Module untuk aplikasi web NodeJS

Ada aplikasi NodeJS yang membutuhkan ES Module. Lalu bagaimana cara aktifkan ES Module? Dengan...

VPS Indonesia cuma 40rb Hosting Gratis Domain

Powered by WHMCompleteSolution