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.

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

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝