php can't connect to mysql with error 13 (but command line can)

后端 未结 3 1016
再見小時候
再見小時候 2020-11-28 06:19

I have weird situation in newly installed server, and it seems that Google can\'t help me this time. I can\'t connect to (remote) mysql from my php-code. When I try to conn

相关标签:
3条回答
  • 2020-11-28 07:07

    On CentOs 6, you can use the following (without -P)

    setsebool httpd_can_network_connect=1
    
    0 讨论(0)
  • 2020-11-28 07:08
    setsebool -P httpd_can_network_connect=1
    

    will also be a helpful CLI command to many people visiting this question, as to allow mysql_connet() connections from within HTTP (Apache) requests to a remote MySQL database server, ensure to enable Network Connections from httpd in SElinux usually located in /etc/selinux/config (disabled by default to prevent hackers from attacking other machines using your httpd).

    0 讨论(0)
  • 2020-11-28 07:10

    On Fedora 21 with apache 2/httpd version 2.6 using php version 5.6 when connecting to a remote mysql server 5.6 or mariadb version 10. It even seems to be a problem connecting to local server when specifying the server's FQDN instead of localhost in the php code.

    This command will fix the permissions problem for the current session:

    setsebool httpd_can_network_connect_db on
    

    To make the fix permanent for subsequent reboots you need to do this:

    setsebool -P httpd_can_network_connect_db on
    

    Thanks to all on this question for rescuing me from "permission denied" hell. :)

    0 讨论(0)
提交回复
热议问题