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
SQLSTATE[HY000] [2002] Permission denied
First you need to check is SELinux enabled with this command:
[root@serverdiary ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: disabled
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
Or you can see on /etc/selinux/config
SELINUX=enforcing
There are 3 options for SELinux:
- enforcing – SELinux security policy is enforced.
- permissive – SELinux prints warnings instead of enforcing.
- disabled – No SELinux policy is loaded.
You can change to permissive, so SELinux only prints warnings instead of enforcing.
[root@serverdiary ~]# setenforce 0
[root@serverdiary ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: disabled
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
Or, if you still want to use option on SElinux config, apply this command as root and restart apache or php-fpm.
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1
P option means permanent, so after reboot, this option still applied.



Kesinlikle şifre talep etmiyor, bir uygulamaya giri yapmanızı istemiyoruz. Bu şekilde sizden şifre talep eden yerlerden alışveriş yapmamanzı tavsiye ediyoruz.
Thanks so much for giving everyone an exceptionally brilliant possiblity to read in detail from this web site. It really is so terrific and as well , stuffed with a good time for me personally and my office acquaintances to search your website nearly 3 times every week to read the newest secrets you have got. And of course, I’m so usually contented considering the magnificent hints you give. Certain 1 facts in this article are absolutely the most beneficial we have all had.