php - netcat "Connection refused" on localhost -
I am trying to get a value from the net cat connection started with a php file, but it dies with it Goes:
Localhost [127.0.0.1] 2000 (?): Connection refused
I do not know why, but it works well If I do it as ssh (www-data) as apache user, I have done this:
1) Start an endless loop serving a date with a little longer. R:
$ (while true; -l -p 2000-c "sleep 5; date" done;) & amp; 2) Check what is happening: $ su www-data $ nc Localhost 2000 Fri 16 Oct 21:33:20 Cote 2009
3) Create /var/www/test.php as follows:
& lt; Pre & gt; & Lt ;? Php exec ('nc localhost 2000 & gt; & gt; / var / www / dates.txt 2 & gt; & gt; /var/www/errors.txt & amp;';); ? & Gt; & Lt; / Pre & gt;
4) Run it on a browser:
http://myserver.com/test.php
5) Finally, take a look at both the txt, the dates are empty (nothing like the response in # 2) and the errors in "Connection refused" error.
The server is a LAMP cluster running Ubuntu Server 9.04 with DBBD and Heartbeat.
What's driving me crazy is that this test.php works well in my laptop (LAMP at Ubuntu Desktop 9.04) and the server already has to open and listen to ports: $ Netstat -ntpl Active Internet connection (server only) Send Proto Rescue-Q - Q Local Address Foreign Address State PID / Program Name TCP 0 0.0.0.0:4743 0.0 .0.0: * LISTEN 2326 / OpenHedged TCP 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3364 / ISSPLD TCP 0 0 0.0.000000 0.0.0.0:* LISTEN 9510 / NC TCP 0 0.0.0.0:80 0.0.0.0:* LISTEN 3470 / Apache 2 TCP 0 0.0.0.0:22 0.0.0.0:* LISTEN 2320 / SSD TCP 0 0 127.0.0.1:3551 0.0.0.0:* LISTEN 2354 / APCPUSD TCP 6 0 0::22 ::: * LISTEN 2320 / SSDD
I think this is a Programming related questions are correct, please do not close it without any comments.
Thanks in advanced!
OK, this was a permission problem after all. Setting / sudoers:
www-data ALL = NOPASSWD: / bin / nc
Comments
Post a Comment