I have Godaddy Shared Web Hosting I need to host node.js website can host site? [closed]
Asked Answered
S

6

33

Anyone have an idea to host a site or reference for how to install a node server on Godaddy. We have Godaddy shared hosting which provides full Cpanel and looking to customize this shared hosting. What is the step to follow and Is we can able to customize this kind of hosting with editing in the Cpanel setting?

I had tried to host the Node.js website bu not able to get up and running it's shows the pure HTML coded website, not User Interface.

Sweetandsour answered 20/10, 2016 at 5:23 Comment(3)
We got the solution as GoDaddy enable the Node and Python Hosting on the Shared plan.Sweetandsour
Hey Bhavik. Can you share the link. They are saying to take a VPS and not shared hosting. I am a bit confused with the same. Facing the same questions as you areMaugre
in my gatewayforweb server -> when i put command node app.js -> it says permission denied. what is the solution of this?Diarist
D
41

Yes this is possible. Somehow I have never seen anyone actually answer this question correctly. This works with the most basic shared hosting plans. I have successfully been able to set it up a couple different ways. I think the second is probably what you want :

1. cgi-node http://www.cgi-node.org/home

Basically this replaces PHP on the lamp stack. You can run javascript through node like you would run PHP. This has all the same functionality of node js but is only really geared towards template rendering.

    <html>
    <body>
     <?
       var helloWorld = 'Hello World!'; 
       write(helloWorld + '<br/>'); 
     ?>
     <?= helloWorld ?>
    <br/>
    <b>I can count to 10: </b>

    <?
      for (var index= 0; index <= 10; index++) write(index + ' ');  
    ?>
      <br/>
      <b>Or even this: </b>
    <?  
      for (var index= 0; index <= 10; index++) { 
    ?>
        <?= index ?> 
    <? } ?>

    </body>
</html>

OR

2. Standalone Server (this works with NameCheap hosting and GoDaddy shared hosting)

In your shared hosting account you will need SSH in order to do this. So you may need to upgrade or request SSH access from their customer support. Download the latest NodeJS https://nodejs.org/en/download/. The shared hosting is probably in linux 64 bit. You can check this on linux or unix by running :

uname -a

Download the Linux binaries and put the bin/node (and the bin/npm file if you want to use npm on the server) file from the download in /home/username/bin/ (create the bin folder if it doesn't exist) on the server. Put permissions 755 on the node binary. So you should have a new file here :

/home/username/bin/node

Open up the .htaccess file in /home/username/public_html and add the following lines :

RewriteEngine on
RewriteRule  (.*)  http://localhost:3000/$1  [P,L] 

Create a file in /home/username/public_html and just call it app.js. Add the following lines in that file :

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('NodeJS server running on Shared Hosting\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

SSH into the server run these commands :

cd /home/username/public_html
which node # this should return ~/bin/node
node app.js & # This will create a background process with the server running

If you can get this set up right this will save you a ton of money in the long run as opposed to using something like AWS or Heroku etc.

Drench answered 14/2, 2017 at 19:43 Comment(10)
Thanks nebulr for this, it has been a massive help! One question, when I close my ssh terminal it stops the node app from running. How do I start the app through cpanel to keep it running.Charolettecharon
Thats odd the node app.js & should take care of that since the & indicates it should run the application in the backgroundDrench
You're right! sorry I missed the & from the end. Thanks massive help!Charolettecharon
I am following the guide at: ferugi.com/blog/nodejs-on-godaddy-shared-cpanel I almost have everything configured but I am having a problem with the .htaccess portion. When adding it for my site, I get an Internal server configuration error. I can run my node app in SSH bash just fine so I know it's working. Any ideas what could be wrong?Cosgrave
@Cosgrave do you have any error codes I can see?Drench
@Drench See #52938907Cosgrave
How much stable is this process ? If traffic increase then it will be stable to crashed? @DrenchStain
I cannot route. Like localhost/dance works. But domain.com/dance goes back to the home pageWilbertwilborn
in my gatewayforweb server -> when i put command node app.js -> it says permission denied. what is the solution of this?Diarist
Hi, your link for cgi-node cgi-node.org/home doesn't work anymore.Experienced
L
39

Yes, this is possible on even the cheapest shared hosting tier. @nebulr instructions are correct. Here is a slightly updated and expanded version for noobs like me.

(1) Enable SSH on your shared hosting account:

Log into your GoDaddy hosting and turn on SSH Access (on the Dashboard, it's in "Settings" on the bottom right). Take note of the cPanel login username and change the password if you don't remember it. Note that you also may need to create keys in CPanel, under "Security" and "SSH Access".

(2) Install the nodejs program itself:

Download the Node.js binaries from https://nodejs.org/en/download/ Specifically you'll want the Linux x64 version (direct link https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz)

Unpack this .tar file on your computer and look inside for the bin folder (on a Mac you may need a program such as The Unarchiver to unpack it). The bin folder will have a file called "node" that's about 40Mb. This "node" file is the only thing we're going to use in this package.

Using the CPanel File Manager or FTP program, create a folder on the server called "bin" in /home/yourUserName/ and give it permissions of 755. Note this is NOT inside public_html.

Upload the "node" file to /home/yourusername/bin/

(3) Create a simple nodejs script:

Open a text editor (like Sublime) and create a new file called "app.js" (or whatever):

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('NodeJS server running on Shared Hosting\n');
});

server.listen(port, hostname, () => {
  console.log('Server running at http://${hostname}:${port}/');
});

Note that this is just the basic server app from https://nodejs.org/en/docs/guides/getting-started-guide/

Open your CPanel File Manager or FTP program, and upload the app.js file to /home/yourusername/public_html/

(4) Modify the .htaccess file:

Use your FTP program to add these lines to the .htaccess file:

RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
Note that the .htaccess file is probably blank by default. Also note that you can use nano, vim, or emacs in SSH to edit the .htaccess file if you're brave or 1337.


(5) Start the node server:

SSH into the godaddy server by opening Putty (Windows) or Terminal (Mac) and at the command line type: ssh [email protected] (where username is your hosting account's cPanel login) The server should respond with [email protected]'s password: which is where you enter the cPanel login password.

Note: If it's your first time SSH'ing to the server, you'll get a message: The authenticity of host 'X.X.X.X' can't be established. RSA key fingerprint is XXXX. Are you sure you want to continue connecting (yes/no)? Type yes and continue on.

Navigate to /home/yourUserName/public_html/ by typing cd public_html. Start the node server script by typing: node app.js & In a couple seconds you should see the message: Server running at http://127.0.0.1:3000/

(6) Check it out:

Open a web browser and type your website's URL. You should get a white page with the text NodeJS server running on Shared Hosting or whatever message you put in line 9 of app.js above. Note that you can't use the IP address on a shared hosting account, you need to use the domain name.

Lashondra answered 10/1, 2019 at 2:19 Comment(10)
Awesome - It is working. You just saved me lots of money I would have spent on cloud.Millwright
Thank you for this! My only concern is...how do you stop it? I can't seem to stop the server. Any solution?Earth
Thank you so much, but how do you make this work with https? I have been trying for days. Is there any simple solution?Beal
So so good. Outstanding!!!Simonette
What is the website URL? Do I go to a subdirectory? I'm afraid that my existing Wordpress page will disappear if I do this...Brubaker
will it be able to install NPM packages ?Simmers
in my gatewayforweb server -> when i put command node app.js -> it says permission denied. what is the solution of this?Diarist
Walter to stop the process from running you would open the cpanel terminal and type 'pkill node' that will stop all node processes from running.Marauding
Am getting permission denied after following the above instructions.Rainey
TO get https working with node and your site on godaddy refence this link godaddy.com/resources/in/web-pro-in/…Marauding
K
7

I installed node on godaddy shared hosting with multiple domains by:

  1. SSH to the godaddy server

  2. Install nvm in the home folder

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash  
    
  3. nvm install 10.14.0 (or the preferred node version) Note: if you get nvm command not found when doing $nvm --version, just close and restart the SSH terminal

  4. In the folder of the site you want to run the node app, add the .httaccess file

    ~/public_html/site folder/.htaccess
    

    RewriteEngine on

    RewriteRule (.*) http://localhost:3000/$1 [P,L]
    

note: .htaccess can be used to target individual folders and changes take effect immediately without having to restart the server.

  1. Run your app.js or node server in the site folder as @nebulr indicated

    $node app.js &
    
Kessia answered 29/11, 2018 at 21:39 Comment(3)
I talked to godaddy guys . they said ssh access is not provided with shared hostingTabina
in step 3. throws error: node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by node) (Goddady shared hosting server)Marzi
ssh is available with shared hosting on godaddy.Marauding
E
3

One other way to do this is via NVM. First get connected to your server using SSH. Then there's a curl command allowing you to install NVM through a bash script :

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

For me, two additional steps were necessary :

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Sources:

Engage answered 30/8, 2018 at 12:24 Comment(0)
G
2

As @nebuir states it is possible to run your node.js developed app using GoDaddy's shared host option because I just did it. The .htaccess portion is extremely key to making this work. The only other line I needed to add was

RewriteRule ^index.html.var$ http://www.yoursite.com:3000/$1 [L,P,QSA]

before

RewriteRule  (.*)  http://www.yoursite.com:3000/$1  [P,L]
Gorse answered 6/5, 2018 at 1:21 Comment(1)
Did not work at allProfessionalize
L
1

You have two choices to host node app. - Either buy your own VPS server from godaddy or digitalocean, etc.. - Godaddy itself provide the option to run their node instances. please refer https://in.godaddy.com/pro/one-click-installation/node-js

Longtin answered 20/10, 2016 at 5:29 Comment(3)
Yes, I have Shared hosting on Godaddy.Sweetandsour
Is their any tips i can run node.js site on my shared hosting ?Sweetandsour
@BhavikLimbani: Not shared hosting. It's their own node instances which runs on VPS.Longtin

© 2022 - 2024 — McMap. All rights reserved.