Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to connect to port 8080: Connection refused Error number: 7 (cURL)

Tags:

linux

php

curl

I have the following code -

$url = 'http://52.77.156.123:8080/LebuPay/check-payment';

$ch = curl_init($url);

$data = array(
"successURL"  =>  'http://jsonviewer.stack.hu',
"failureURL"  =>   'http://jsonviewer.stack.hu',
"amount"  => $amount,
"orderTransactionID"  => $order_id,
"firstName" =>   "",
"lastName"  =>  "",
"email" => "",
"mobileNumber"  => "",
"accessKey" =>  "some_random_key"
);

$jsonEncode = json_encode($data);

curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonEncode);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$result = curl_exec($ch);
$result = json_decode($result, true);

echo "Error CURL: " . curl_error($ch) . " \nError number: " . 
curl_errno($ch);

curl_close($ch);


$token = $result['token'];
header("location: http://52.77.156.123:8080/LebuPay/execute-payment?token=$token");

The code works on my localhost but when I upload it on the server (Godaddy linux). It gives me error "Failed to connect to 52.77.156.123 port 8080: Connection refused Error number: 7"

The API I'm trying to get response from is hosted on AWS.

Any idea how I can solve this problem? Thanks.

like image 265
Khairul Alam Avatar asked Nov 07 '25 10:11

Khairul Alam


1 Answers

Since the problem occurs when you changed the server, I would suspect that the problem is the outgoing server blocking the port.

This, admittedly old, forum post says:

I don't know if it applies to anything other than shared hosting, but Godaddy shared hosting has all outgoing ports other than 80 blocked by their firewall

and

The problem is that Godaddy shared hosting will not let you make requests from your site that go to any port other than 80.

It's like having a house where all of the doors and windows, except the front door, are welded shut.

and

Talked to Godaddy Support and was told port 8080 is blocked, even on their dedicated servers.

This might have changed in the meantime, but since you are experiencing the problem I don't think it has.


Possible solutions:

  • Don't use awful hosting (Godaddy has a terrible reputation)
  • Somehow persuade Godaddy to open up the port
  • Find a proxy that lets you use port 80 to get the request outside of Godaddy's network
like image 132
Quentin Avatar answered Nov 10 '25 00:11

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!