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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

-2

what happens if you

 telnet 10.1.150.109 5672

7 Comments

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!')
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."
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.
great, glad you sorted it out. bye
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.