Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to for once leave selinux running on a server for the alleged increased security.
I usually disable selinux to get anything to work.
How do I tell selinux to allow mysql connections?
The most documentation I've found is this line from mysql.com:
If you are running under Linux and Security-Enhanced Linux (SELinux) is enabled, make sure you have disabled SELinux protection for the mysqld process.
wow ... that's really helpful.

share|improve this question

migrated from stackoverflow.com Feb 24 '11 at 23:20

This question came from our site for professional and enthusiast programmers.

1  
Please provide all of the following information for us to have a chance of helping you. 1. Linux Distro and Version, 2. MySQL version and installation source, 3. AVC log entries from a denied connection, 4. Relevant MySQL logs, if any 5. The output of getsebool -a | grep mysql 6. Exact steps you have taken to reproduce this –  hobodave Feb 24 '11 at 23:25
add comment

6 Answers 6

To check SELinux

sestatus

To see what flags are set on httpd processes

getsebool -a | grep httpd

To allow Apache to connect to remote database through SELinux

setsebool httpd_can_network_connect_db 1

Use -P option makes the change permanent. Without this option, the boolean would be reset to 0 at reboot.

setsebool -P httpd_can_network_connect_db 1
share|improve this answer
add comment

Do you get an error? What flavor of linux are you using? Security context is a good place to start if you are getting an error. ls -Z will give context... But your question is very vague.

share|improve this answer
    
I am connecting from a windows box. There is no error ... the connection is just refused and the page times out. I know if I turn off selinux everything will be fine. –  xivix Feb 24 '11 at 21:17
    
since the connection is incoming from a windows box, ls -Z only gives me info about the files in whatever directory I'm in on the linux box. –  xivix Feb 24 '11 at 21:18
    
In my question above I cited a mysql reference ... which said to disable selinux protection for the mysqld process ... but it doesn't say how to do that :( Nor can I find out how. –  xivix Feb 24 '11 at 21:20
    
Anything in the logs on the linux box? selinux can stop httpd from making a socket connection... –  Tamler Feb 24 '11 at 21:35
    
Nothing in messages or secure logs ... is there a particular log you had in mind? –  xivix Feb 24 '11 at 21:46
show 3 more comments

Apparently configuring selinux isn't trivial. You may wish to start here.

setenforce 0

puts selinux into permissive mode, where it allows anything but logs what it's allowing. A reboot or

setenforce 1

returns to blocking whatever the policy doesn't permit.

Check out these selinux policy docs for mySQL in Fedora.

share|improve this answer
add comment

Are you sure it's selinux? Normal connections from outside should be allowed by selinux. So it could also be the firewall. If you have local services trying to connect to mysqld, that's something different: http://docs.fedoraproject.org/en-US/Fedora/13/html/Managing_Confined_Services/sect-Managing_Confined_Services-MySQL-Booleans.html

share|improve this answer
add comment

The ausearch command can help find the error log.

share|improve this answer
    
ausearch -m avc -ts today | audit2why , command can suggest solution –  vnix27 Feb 26 '11 at 7:01
add comment

you can build local policy too:

"You can generate a local policy module to allow this access.Do allow this access for now by executing:"

grep httpd /var/log/audit/audit.log | audit2allow -M mypol

semodule -i mypol.pp

or enable globally for the actual session:

setsebool httpd_can_network_connect_db 1ode here

or permanent:

setsebool -P httpd_can_network_connect_db 1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.