William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

redis server predis permission denied: setsebool

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://]’

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: