5

OS: CentOS 6.4
I am trying to connect to the RabitMQ server using the php client as follows,

$connection = new AMQPConnection('10.1.150.109', 5672, 'guest', 'guest');
$channel = $connection->channel();

But when I ran the script from the browser, it gives me this,
exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Error Connecting to server(13): Permission denied ' in /var/www/html/event/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:27

netstat show this,
tcp 0 0 :::5672 :::* LISTEN 10776/beam

In this post, this guy gives the answer implicitly, Client can't connect to RabbitMQ server on localhost. But he has not described the procedure which he followed to fix the issue.

I thank you in advanced for anyone who can help me in this regard.

Community
  • 1
  • 1
Tharanga
  • 115
  • 2
  • 2
  • 7

2 Answers2

7

Since I don't like the accepted answer, here's one I think is better.

Disabling SELinux is a hack. It may work but it's probably not a good idea. What isn't immediately obvious from the question (or the other question it references) is HOW the php client is being run. I.e. from the command line or via a browser.

SELinux by default won't allow httpd (i.e. apache) to connect to port 5672.

In my case, running the php script from the command line works - the connection is accepted. However, running it from a browser fails because of this SELinux policy.

I imagine that "reconfiguring the listen address from 0.0.0.0 to 127.0.0.1" is a reference to the hostname parameter, which in my case is set to "localhost" rather than an explicit IP address. (For sure 0.0.0.0 is going to fail!)

You can enable httpd to access port 5672 in SELinux: https://serverfault.com/questions/563872/selinux-allow-httpd-to-connect-to-a-specific-port

Community
  • 1
  • 1
geoidesic
  • 4,649
  • 3
  • 39
  • 59
-2

what happens if you

 telnet 10.1.150.109 5672
sathia
  • 2,192
  • 2
  • 24
  • 42
  • thank you for you time, but it says: Connection closed by foreign host. Is this a permission issue with the webserver(apache) as if I run the php script in command line, it works perfectly by pushing the message to the server. (php /var/www/html/event/send.php [x] Sent 'Hello World!') – Tharanga Feb 17 '14 at 12:55
  • ok, apparently you can connect to the server, the guy says on the post you linked: "Problem was fixed with reconfiguring listen address form 0.0.0.0:5672 to 127.0.0.1:5672 and small security fixes in OS." – sathia Feb 17 '14 at 13:01
  • I was digging more into the server and managed to fix the problem by disabling selinux ($ echo 0 > /selinux/enforce). Thank you again for your time. – Tharanga Feb 17 '14 at 13:11
  • great, glad you sorted it out. bye – sathia Feb 17 '14 at 13:12
  • 2
    I don't see how a question can be accepted as an answer. I'm suffering from the same problem and this has left me none the wiser as to a solution. Just noticed that the person who wrote this question is complaining of exactly what I'm complaining of - no actual answer to the question... yet he accepts a solution that doesn't answer the question. Oh dear. – geoidesic Jan 02 '15 at 09:10
  • I'll rephrase for you: what happens if you telnet 10.1.150.109 5672 – sathia Jan 02 '15 at 09:17
  • Yes, this should have been a comment and not an answer. – BPS Sep 28 '18 at 13:11