I have a new CentOS server set up, with Apache and php-fpm.

The php application fails to connect to an external MySQL server. This server is reachable from other servers, the firewall on the database server isn't the problem.

I've checked the apache and php-fpm logs, but I can't find any clues there. If I connect to the external database through MySQL on the CentOS server there's no problem, but the php application fails.

This makes me conclude that the route from client to database server is without obstacles, but that CentOS 7 or php-fpm causes trouble somewhere.

Someone any idea what this could be? I don't know where else to look. Perhaps some new security changes in CentOS 7 that I'm not aware of?


This is probably a SELINUX-related problem. Try the following (in preference order):

  1. setsebool httpd_can_network_connect_db on
    If it works, make it permanent using the "-P" flag. If it does not work, go to step 2:
  2. setsebool httpd_can_network_connect on
    As above, if it works, use the "-P" flag. Otherwise, go to step 3:
  3. setenforce 0
    This will put SELINUX into permissive (ie: non-blocking) mode. If it works, you should try to understand what is causing selinux to block your connection (tail -f /var/log/audit/audit.log is a good place to start).

If you can't figure why selinux is blocking you, you can set it to permanently to permissive mode by editing the file /etc/selinux/config

  • Hi shodanshok, thanks for your answer. I figured it out just before you answered. It was indeed a SELinux problem (only option that was left..). See my answer below :) – Keugels Apr 16 '15 at 9:55
  • Consider marking the reply as the answer, as that would be useful for other readers ;) – shodanshok Apr 16 '15 at 10:27

I was just 30 minutes too early posting this question. There was a SELinux variable I didn't know of: httpd_can_network_connect. Setting this on solved the problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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