How to SELinux allow Apache or PHP-FPM connect remote MySQL

How to SELinux allow Apache or PHP-FPM connect remote MySQL

If you have trouble apache or PHP-FPM can not connect to remote MySQSL server, example error on PDO connection on remote server like below

First you need to check is SELinux enabled with this command:

Or you can see on /etc/selinux/config

There are 3 options for SELinux:

  1. enforcing – SELinux security policy is enforced.
  2. permissive – SELinux prints warnings instead of enforcing.
  3. disabled – No SELinux policy is loaded.

You can change to permissive, so SELinux only prints warnings instead of enforcing.

Or, if you still want to use option on SElinux config, apply this command as root and restart apache or php-fpm.

P option means permanent, so after reboot, this option still applied.

Leave a Reply

Your email address will not be published. Required fields are marked *