Could not bind socket : Permission denied












0















I would like to use port 443 in a PHP script, but seems like i don't have privilages to do so.
That's the php error that occurs:



Could not bind socket : [13] Permission denied


that's the simple php code:



<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/scripts/php/outputWhile.php");
$ip = "0.0.0.0";
$port = "443";

error_reporting(~E_WARNING);
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0))){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg n");
}

// Bind the source address
if( !socket_bind($sock, $ip , $port) ){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg n");
}

while(true){
$messageRecieved = "";
$r = socket_recvfrom($sock, $messageRecieved, 512, 0, $remote_ip, $remote_port);
echo $messageRecieved . "<br>";
}


?>



How can i give root privileges to that script?
I suppose i should add the user to the root group, but.. which user?



I'm using Amazon AWS VPS with Red Hat 7.2.1-2 distro, with Apache and LiteSpeed Web Server.



Thanks,
Davide.










share|improve this question























  • A simple solution would be to add a NAT rule to redirect between port 443 and port 4430. Then your script can interact with port 4430 and have outbound and inbound datagrams renumbered. I've never tried that with UDP, but I can't think of any reason it wouldn't work.

    – David Schwartz
    Dec 20 '18 at 0:34













  • @DavidSchwartz If i use NAT will the packet still be sent using the main protocol or would it change something? I need to exchange packet from a php client to a php server using QUIC protocol.

    – Fanto
    Dec 20 '18 at 11:12











  • Port NAT just allows the application to use port 4430 to send and receive datagrams that are actually sent from and to port 443. It has no effect on the protocol layered on top of UDP.

    – David Schwartz
    Dec 20 '18 at 17:14
















0















I would like to use port 443 in a PHP script, but seems like i don't have privilages to do so.
That's the php error that occurs:



Could not bind socket : [13] Permission denied


that's the simple php code:



<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/scripts/php/outputWhile.php");
$ip = "0.0.0.0";
$port = "443";

error_reporting(~E_WARNING);
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0))){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg n");
}

// Bind the source address
if( !socket_bind($sock, $ip , $port) ){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg n");
}

while(true){
$messageRecieved = "";
$r = socket_recvfrom($sock, $messageRecieved, 512, 0, $remote_ip, $remote_port);
echo $messageRecieved . "<br>";
}


?>



How can i give root privileges to that script?
I suppose i should add the user to the root group, but.. which user?



I'm using Amazon AWS VPS with Red Hat 7.2.1-2 distro, with Apache and LiteSpeed Web Server.



Thanks,
Davide.










share|improve this question























  • A simple solution would be to add a NAT rule to redirect between port 443 and port 4430. Then your script can interact with port 4430 and have outbound and inbound datagrams renumbered. I've never tried that with UDP, but I can't think of any reason it wouldn't work.

    – David Schwartz
    Dec 20 '18 at 0:34













  • @DavidSchwartz If i use NAT will the packet still be sent using the main protocol or would it change something? I need to exchange packet from a php client to a php server using QUIC protocol.

    – Fanto
    Dec 20 '18 at 11:12











  • Port NAT just allows the application to use port 4430 to send and receive datagrams that are actually sent from and to port 443. It has no effect on the protocol layered on top of UDP.

    – David Schwartz
    Dec 20 '18 at 17:14














0












0








0








I would like to use port 443 in a PHP script, but seems like i don't have privilages to do so.
That's the php error that occurs:



Could not bind socket : [13] Permission denied


that's the simple php code:



<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/scripts/php/outputWhile.php");
$ip = "0.0.0.0";
$port = "443";

error_reporting(~E_WARNING);
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0))){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg n");
}

// Bind the source address
if( !socket_bind($sock, $ip , $port) ){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg n");
}

while(true){
$messageRecieved = "";
$r = socket_recvfrom($sock, $messageRecieved, 512, 0, $remote_ip, $remote_port);
echo $messageRecieved . "<br>";
}


?>



How can i give root privileges to that script?
I suppose i should add the user to the root group, but.. which user?



I'm using Amazon AWS VPS with Red Hat 7.2.1-2 distro, with Apache and LiteSpeed Web Server.



Thanks,
Davide.










share|improve this question














I would like to use port 443 in a PHP script, but seems like i don't have privilages to do so.
That's the php error that occurs:



Could not bind socket : [13] Permission denied


that's the simple php code:



<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/scripts/php/outputWhile.php");
$ip = "0.0.0.0";
$port = "443";

error_reporting(~E_WARNING);
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0))){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg n");
}

// Bind the source address
if( !socket_bind($sock, $ip , $port) ){
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg n");
}

while(true){
$messageRecieved = "";
$r = socket_recvfrom($sock, $messageRecieved, 512, 0, $remote_ip, $remote_port);
echo $messageRecieved . "<br>";
}


?>



How can i give root privileges to that script?
I suppose i should add the user to the root group, but.. which user?



I'm using Amazon AWS VPS with Red Hat 7.2.1-2 distro, with Apache and LiteSpeed Web Server.



Thanks,
Davide.







linux apache-http-server php sockets






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 19 '18 at 23:28









FantoFanto

1




1













  • A simple solution would be to add a NAT rule to redirect between port 443 and port 4430. Then your script can interact with port 4430 and have outbound and inbound datagrams renumbered. I've never tried that with UDP, but I can't think of any reason it wouldn't work.

    – David Schwartz
    Dec 20 '18 at 0:34













  • @DavidSchwartz If i use NAT will the packet still be sent using the main protocol or would it change something? I need to exchange packet from a php client to a php server using QUIC protocol.

    – Fanto
    Dec 20 '18 at 11:12











  • Port NAT just allows the application to use port 4430 to send and receive datagrams that are actually sent from and to port 443. It has no effect on the protocol layered on top of UDP.

    – David Schwartz
    Dec 20 '18 at 17:14



















  • A simple solution would be to add a NAT rule to redirect between port 443 and port 4430. Then your script can interact with port 4430 and have outbound and inbound datagrams renumbered. I've never tried that with UDP, but I can't think of any reason it wouldn't work.

    – David Schwartz
    Dec 20 '18 at 0:34













  • @DavidSchwartz If i use NAT will the packet still be sent using the main protocol or would it change something? I need to exchange packet from a php client to a php server using QUIC protocol.

    – Fanto
    Dec 20 '18 at 11:12











  • Port NAT just allows the application to use port 4430 to send and receive datagrams that are actually sent from and to port 443. It has no effect on the protocol layered on top of UDP.

    – David Schwartz
    Dec 20 '18 at 17:14

















A simple solution would be to add a NAT rule to redirect between port 443 and port 4430. Then your script can interact with port 4430 and have outbound and inbound datagrams renumbered. I've never tried that with UDP, but I can't think of any reason it wouldn't work.

– David Schwartz
Dec 20 '18 at 0:34







A simple solution would be to add a NAT rule to redirect between port 443 and port 4430. Then your script can interact with port 4430 and have outbound and inbound datagrams renumbered. I've never tried that with UDP, but I can't think of any reason it wouldn't work.

– David Schwartz
Dec 20 '18 at 0:34















@DavidSchwartz If i use NAT will the packet still be sent using the main protocol or would it change something? I need to exchange packet from a php client to a php server using QUIC protocol.

– Fanto
Dec 20 '18 at 11:12





@DavidSchwartz If i use NAT will the packet still be sent using the main protocol or would it change something? I need to exchange packet from a php client to a php server using QUIC protocol.

– Fanto
Dec 20 '18 at 11:12













Port NAT just allows the application to use port 4430 to send and receive datagrams that are actually sent from and to port 443. It has no effect on the protocol layered on top of UDP.

– David Schwartz
Dec 20 '18 at 17:14





Port NAT just allows the application to use port 4430 to send and receive datagrams that are actually sent from and to port 443. It has no effect on the protocol layered on top of UDP.

– David Schwartz
Dec 20 '18 at 17:14










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1386087%2fcould-not-bind-socket-permission-denied%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1386087%2fcould-not-bind-socket-permission-denied%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

Алькесар

Josef Freinademetz