• Blogs (9)
    • šŸ“± 236 - 992 - 3846

      šŸ“§ jxjwilliam@gmail.com

    • Version: ā€šŸš€ 1.1.0
  • redis server predis permission denied: setsebool

    Blogs20132013-07-19


    redis server predis permission denied: setsebool

    It is quite strange to throw errors when php codes access local MongoDB or Redis-server. e.g.: locally in CentOS 6.3, the redis-server runs as daemon, when I use phpMoAdmin(phpmoadmin.com) to connect it, it throws error like this:

    PHP Fatal error: Uncaught exception ā€˜Predis\Connection\ConnectionException’ with message ā€˜Permission denied [tcp://127.0.0.1:6379]’

    I checked the default dirs (/var/log/, /var/run/, /var/lib/ etc) for permission, also the owner/group, test without port 80, it seems work fine. But when in browser or curl to access, it failed.
    Finally I got the answer from stackoverflow: Troubleshooting ā€œPermission deniedā€ when attempting to connect to Redis from PHP script: By default, SELinux does not allow Apache to make socket connections. To solve it, should run the following command first:

    sudo /usr/sbin/setsebool httpd_can_network_connect=1 sudo setsebool -P httpd_enable_homedirs 1

    Here is a detailed explain:

    httpd scripts by default are not allowed to connect out to the network. This would prevent a hacker from breaking into you httpd server and attacking other machines. If you need scripts to be able to connect you can set the httpd_can_network_connect boolean on.

    setsebool -P httpd_can_network_connect 1

    I wrote the /usr/sbin/setsebool httpd_can_network_connect=1 in /etc/profile, so no worry for MongoDB and Redis-server connection anymore.
    Actually I met this before, and run the same command to solve it, but forgot this time, so write here for retrieve. More info is available at: SELinux/apache.