Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Client can't connect to RabbitMQ server on localhost

Tags:

php

rabbitmq

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.

like image 334
Tharanga Avatar asked Feb 17 '14 12:02

Tharanga


1 Answers

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

like image 124
geoidesic Avatar answered Sep 24 '22 02:09

geoidesic