Why can’t I bind to this socket in PHP?

  apache, apache2, php, ubuntu, windows

I am running an apache2 server from a windows computer using the Linux subsystem. Now I’m trying to use it as a server and listen to connections. Unfortunately it is failing when trying to bind to the socket. This is the code:

$host = '0.0.0.0';
$port = 1433;

set_time_limit(0);

if(!$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) {
    die("Couldn't create socket! reason: " . socket_strerror(socket_last_error()) . "n");  
}

if(!$result = socket_bind($socket, $host, $port)) {
    die("Couldn't bind socket! reason: " . socket_strerror(socket_last_error()) . "n");    
}

The error code just states that permission is denied, however I have allowed this specific port through my firewall. I am quite new to the whole php server-side thing, so I would really appreciate any help!

Source: StackOverflow

LEAVE A COMMENT