0

I'm trying to execute nodejs with php, do this it's really simple

<? shell_exec("node app.js &"); ?>

My nodejs file creates a server with express.

var express = require("express"),
app         = express();

app.get('/', function(request,response)
{
  response.status(200).send("Welcome");
});

app.listen(82, 'localhost', function(){console.log("Server are running on port 82");});

When the file runs this is the output

Error: listen EACCES 127.0.0.1:82

at Object.exports._errnoException (util.js:873:11)

at exports._exceptionWithHostPort (util.js:896:20)

at Server._listen2 (net.js:1237:19)

at listen (net.js:1286:10)

at net.js:1395:9

at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:64:16)

at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:83:10)

The port is open, this is the output for "service iptables status" command

20 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:81:90

I think the error is because apache (apache runs on port 80) don't have permission to create a server

Someone have any idea of how solve this?

1
  • 1
    1. You need super user privileges to bind a low port. 2. Normally you just leave node running, like apache. Commented Jul 13, 2016 at 22:20

1 Answer 1

1

You will either need to grant the process that starts the node.js app higher privileges so it can use such a low port number or you can use a higher port number (higher than 1024) that is not so restricted. For example, port 3000 is common.

Some people also work-around this by starting their server on a higher port (like 3000) and then using iptables to forward incoming requests from a low port (like the 82 you were using) to port 3000. This allows your server to run without needing the higher privileges, but it can still "work" on the lower port number.

Here's more discussion of work-arounds: Is there a way for non-root processes to bind to "privileged" ports on Linux? and How can I run a server on Linux on port 80 as a normal user?.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.