I have an issue that is most probably a user rights issue.
I have a php script that connects using PDO to a sphinx db.
$sp = new PDO('mysql:host=127.0.0.1;port=9306;dname=', '', '');
When I run it from terminal using root account it works fine. But, when I attempt to run it through browser as user apache I get the following error:
[Thu Mar 20 11:22:51 2014] [error] [client 98.12.26.274] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13)' in /var/www/html/surveys/test.php:3
Stack trace:
#0 /var/www/html/surveys/test.php(3): PDO->__construct('mysql:host=127....', '', '')
#1 {main}
thrown in /var/www/html/surveys/test.php on line 3
There has to be something that is missing the propoer user rights but I have no clue what files I need to give rights to for this to work.
UPDATE: I realized that selinux was blocking the port. How do I enable that port for apache using selinux?
Just use a socket instead of the IP address? See the manual for an example. This circumvents the network stack altogether.
Put something like
listen=/tmp/mysql_sphinx.sock
into the sphinx.cnf and put the same socket into the DNS of PDO like
$db = new PDO('mysql:dbname=testdb;unix_socket=/tmp/mysql_sphinx.sock');
This frees you from the need to make MySQL accessible over the network too. This is better taking security into account.