GithubHelp home page GithubHelp logo

node.php's Introduction

Node.php

Ever wanted to deploy a node.js web app but didn't have money for a dedicated node.js hosting or didn't have time to set up a cloud PaaS? Have an existing PHP shared hosting based on the LAMP stack? Now you can run node.js on top of it!

Node.php originates from my ealier answer on Stack Overflow.

The node.php script installs an official node.js package, starts a hidden server on localhost:49999 with provided JS file and proxies all requests to it.

Warning! This is an alpha version, it may be insecure, run it at your own risk!

Requirements

A PHP web hosting based on Linux with safe mode off and the following functions enabled: curl_exec, exec, passthru.

How to run

  1. Put the node.php file in your public_html (or similar) folder, then install node.js by browsing to: http://example.org/node.php?install.
  2. When succeeded, install your node.js app by uploading its folder or using npm: http://example.org/node.php?npm=install jt-js-sample.
  3. When everything goes fine, start your node.js instance by going to: http://example.org/node.php?start=node_modules/jt-js-sample/index.js.
  4. Now you can request your app by browsing to: http://example.org/node.php?path=optional/request/path. This will return a response from the running node.js app at http://127.0.0.1:49999/optional/request/path.
  5. Finally, stop your node.js server by loading: http://example.org/node.php?stop.

Commands

node.php[?path=some/path] - serves an already running node.js app with an optional request path (no leading slash)

The following commands require the ADMIN_MODE set to true (line 13 of node.php):

node.php?install - downloads and extracts node.js into the node folder.

node.php?uninstall - removes the node folder

node.php?start=node_modules/jt-js-sample/index.js - starts a node.js server running the provided index.js file

node.php?stop - stops a running node.js server

node.php?npm=install jt-js-sample - runs npm install jt-js-sample (may be dangerous!)

Demo

Here is a live demo on a dirt cheap PHP shared hosting.

Troubleshooting

In order to troubleshoot any problems with running node.php, connect to your host using SSH and run exact node.php commands manually:

  1. Go to your document root directory (often ~/public_html/) and check if node directory exists there.

  2. If yes, go to step 3, otherwise download node for your architecture:

    wget http://nodejs.org/dist/node-v5.7.0-linux-x86.tar.gz
    tar -xzf node-v5.7.0-linux-x86.tar.gz
    mv node-v5.7.0-linux-x86/ node/
    rm -f node-v5.7.0-linux-x86.tar.gz
    
  3. Run node on port 49999 (or other): PORT=49999 node/bin/node [path/to/index.js] &

  4. Connect to node instance: curl http://127.0.0.1:49999/[some/path]

  5. If you get the HTML response, the problem most probably lies in PHP and its permissions.

  6. Kill node process: killall node

License

Node.js is developed by Joyent et al. under the MIT License.

Node.php is developed by Jerzy Głowacki under the MIT License.

node.php's People

Contributors

fieu avatar niutech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node.php's Issues

Not working with socket.io module

Hi niutech,

I really love this script. Its working great for node apps, but doesnt seem to be connecting properly for socket.io connections

I've tried implementing even the most basic demo from http://socket.io/demos/chat/ but I cant seem to get it to connect.

Maybe I am missing something. Have you successfully run a socket.io demo on your node.php installation?

Many thanks for a great script! Would be awesome to have the powerful socket.io module working :-)

etherpad-lite what am I missing

Hi, thanks for a great project. I would like to try etherpad-lite so I ran this php on my localhost.
However I can't seem to get past
http://localhost/..../test/node.php?path=node_modules\ep_etherpad-lite\node\server.js
Error requesting node_modules\ep_etherpad-lite\node\server.js: Failed to connect to 127.0.0.1 port 9001: Connection refused
neither with the default 49999 nor with 9001 as portnumber which I believe is requested by etherpad.
What am I missing?
Thanks

exec() has been disabled for security reason

I'm getting this error message when running node.php?start. Any way I can fix this? Thanks!

Node.php

Starting: node ''
Warning:  exec() has been disabled for security reasons in /home/{mysite}/www/node.php on line 70
Failed.

Warning:  file_get_contents(nodeout): failed to open stream: No such file or directory in /home/{mysite}/www/node.php on line 74

Powered by node.php

error -1

Hi there!

Getting an issue when trying to npm install.
First of all I had to manually unpack node, it now says that install succeeded.
But now I am getting:

Running: 
Failed. Error: -1. See npm-debug.log

npm-debug.log returns a 404 page

NPM install error

I am trying to run npm install on my server and it returns:
Node.php

Running: npm node/bin/npm express
Failed. Error: 126

I was trying to install express. Check out my error here: scratchyone.com/runnode/index.php?npm=express

Run Phantomjs & casper JS

Hello
I am They try to run phantomjs with casperjs on my shared hosting but I'm having some problems.
keeps giving me this error

`Starting: node 'node_modules/casperjs'
Done. PID=572210
module.js:341
throw err;
^

Error: Cannot find module '/xxxxx/xxxxx/public_html/node_modules/casperjs'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:141:18)
at node.js:933:3`

Can you help me out? I do not understand how to run the scripts.

mysql req.query not working ...

Hi there,
I´ve try your code and is it amazing. And I've create a test with mysql and every think is fine until I try to get the req. from query .
i.e : http://api.cysub.com/user?name=name&email=email
and you can get the ?name=name&email=email with req.query and it will show somethink like this
{ name: 'name', email: 'email' } with ( console.log(req.query)
but is doen't.
PS / On my test site you can see the last one "test":[] this should print "test":[{ name: 'name', email: 'email' }] if is work.

I´ve creat a control for this node.php like a terminal. You can see its here http://api.cysub.com/?a=setup type help to see the command's.

The terminal css you can get is here from Marcus Bizal.
http://codepen.io/marcbizal/pen/VLKoam

Error: 127 when running on godaddy.com shared hosting

Hi,
I have successfully installed node.js on my website using node.php, however when I try to use npm install to install the samples package or another package I get this output:

capture

Any help would be greatly appreciated. Node.php seems great.
Thanks.

Moving Node install away from public_html

This is a bit of a design discussion, but I feel that the location for the node install should be above the public_html/html folder that node.php resides in, that way it is not as easy to discover on the Internet. Obviously, this MAY not be possible on all shared hosting services, but on the couple I've used it would be.
I suggest move the default install location to ../ and just use public_html/node as a fall-back.

Can I install mongodb via npm?

I tried it. I got this Running: node/bin/npm --cache ./.npm -- install mongodb
Failed. Error: 127. See npm-debug.log
also no log has been created.

Failed to install

Got the following messages:

Installing Node.js:
Failed. Error:
Try putting node folder via (S)FTP, so that >/home/users/htdocs/node/bin/node exists.

What could be the reason? Thanks.

Connection refused error

Hello,

Getting this for all requests in non-admin mode:

Error requesting : Failed to connect to 127.0.0.1 port 49999: Connection refused

Tried opening port with CSF without any luck.

Any specific ideas?

Thanks

Better options available

Not sure how I came across this project, but there are probably better approaches out there that are also affordable. An approach like this is subject to many less-than-ideal solutions, along with opening up some pretty big security holes. You're likely better off cutting out PHP entirely and just sticking with NodeJS on its own.

There are a few services out there that can host NodeJS projects affordably, including Heroku. They've also got a great getting started article with NodeJS: https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

Hope this helps!

Socket.io

how to use socket.io in node.js? how to transfer data from client to node socket.io server or from node socket.io server to client?
I create socket.io server in node.js but can't connect it from client. I use node.php address for socket.io server in client code

Module installation failed

Hi, thank you for that script! Unfortunately I cannot install packages as described:

Running: node/bin/npm --cache ./.npm -- install jt-js-sample
Failed. Error: 127. See npm-debug.log

All files have chmod 0777. Shared space at All-Inkl.com

Any hint how to proceed?

Couldn't connect to host

The demo link in the readme has the same problem as I have on my server. I can install and start the server but when I set the node.php?path=xxx it tells me the following error:

Error requesting xxx: couldn't connect to host.

How to solve this error?

Connection refused

My node js server setup with node-php stop working after few days. I got a success message

Starting: node 'myapp/server.js'
Done. PID=...

while calling http://myserver/node.php?start=myapp
And my server was working properly.

But after few days it started to show an error message
Error: Failed to connect to 127.0.0.1 port 24572: Connection refused

Then I tried to start the node app again but got this message
Node.js is already running. Stop it.

While trying to stop it, got a messge
Stopping Node.js with PID=:
Error = 1.

C++ error while loading my server

I got the following error while starting my server

node/bin/node: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

but when I tryied to run it again it it said it's already running. So I tryied to start the application on

mydomain.com:8888 and I got

Your connection to this server has been blocked in this server's firewall.
You need to contact the server owner for further information.
Your blocked IP address is 177.158.164.97

so I thought it was the port I used (8888) and see that you use port 49999. So I tried 88888 the request just goes on waiting for an answer and never returns. I thinks this is due to the first block.

The program I'm trying to run is very simple (I'm still learning node.js), this one:

var http = require('http');
var url = require('url');
var server = http.createServer(function (req, res) {    
    var postData = url.parse(req.url, true); 
    var result;
    var mdate = moment(postData.query['iso']);
    switch (postData.pathname) {
        case '/host':
            result = "host: " + req.headers.host;
            break;
    }
    if (result) {
        res.writeHead(200, { 'Content-Type': 'application/json' });
        res.end(result);
    } else {
        res.writeHead(404);
        res.end();
    }
}).listen(8888)

I uploaded this file (server.js) to my domain's root. The same dir I installed node.php. And tryied to run it with http://mybuyinglist.com/node.php?start=server.js

I tryed ports 8080 and 9090 with similar results.
Am I doing something wrong ? I find it strange that node.php can run on a high port and mine was blocked.

Edit:

I did some more tests and I'm confident node.php is correctly directing to my file because I add this code to node_start function:

    if(file_exists($file)) {
        echo "$file exists.\n";
        $strfile = file_get_contents($file);
        echo $strfile . "\n";
    } else {
        echo "$file doesn't exists.\n";
        return;
    }

and it correctly dumped my file. So I guess this server doesn't allow node to run, or is there anything else I can do ?

Warning: set_time_limit() has been disabled for security reasons

When running the script at a site on a shared hosting (like 000webhost.com) the warning is shown

Warning: set_time_limit() has been disabled for security reasons

and nothing is installed:

Node.php
Node.js is not yet installed. Switch to Admin Mode and Install it.
Powered by node.php

I guess, it's not possible to install node.js on a free (usually restricted) shared hosting ... or do I miss some workaround?

Switch to admin mode

I am trying to run
/node.php?install
But it is saying me to switch to admin mode. How can i switch to admin mode??
Error::
Node.php

Node.js is not yet installed. Switch to Admin Mode and Install it.
Powered by node.php

Installing Express

I have installed node successfully but I am having issues installing express.

When I try node.php?npm=install+express I get this error:

Error requesting : Failed to connect to 127.0.0.1 port 49999: Connection refused

Can I use Node.php to install express or am I just running in circles?

NPM not working

When I am trying to run node.php?npm=install jt-js-sample Then it is return Failed. Error: 4. See npm-debug.log
I want to install express, socket.io, and mysql via NPM.
How can I did?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.