Skip to content
Advertisement

Cannot connect to Sphinx with PHP and PDO

I seem to be having issues I do not understand…

I have installed MySQL 8.0.27 I have installed Sphinx, created an index, filled it and all is OK through the terminal. Am able to query the Spinx index, without issues. So searchd and the indexer are doing their job.

I have created a simple PHP interface to search through this index with PHP. But this is where things are getting strange…

I am NOT able to connect to the sphinx instance (which does work through the terminal..) –> SQLSTATE[HY000] [2002] Permission denied

My sphinx.conf

JavaScript

This is the Sphinx status

JavaScript

This is the code I use for connecting to Sphinx from my PHP script… Which causes the error mentioned in the top of this post…

JavaScript

Connecting through the terminal is no problem and queries are working fine and fast…

JavaScript

It failes on the $pdo = new PDO() part. Cannot make connection. I have tried replacing localhost with 127.0.0.1, have tried replacing the port to 9312 (see config) and all combinations between these. No dice.

Does anybody have a clue or a tip? It is driving me mad…

Advertisement

Answer

Just installed Manticore Search 4.2 and it had the exact same issue… So that got me thinking.

Turns out it was because of SELinux… This post had the solution for me. So it had nothing to do with Sphinx or Manticore Search… It was my SELinux settings that prevented me from making Database connections from http user.

The answer has 4 simple steps to permanently allow that and everything works like a charm!

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement