dongwalun2507 2014-03-20 15:25
浏览 106
已采纳

PDO Sphinx连接用户权限(SELINUX问题)

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?

  • 写回答

1条回答 默认 最新

  • dtxob80644 2014-03-20 15:59
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?