在LNMP使用過程中,使用mysqli_connect()鏈接mysql數(shù)據(jù)庫時(shí)炭菌,出現(xiàn)以下錯(cuò)誤
Could not connect: Can't connect to MySQL server on '127.0.0.1' (13)
使用下面命令查看時(shí)
#getsebool -a | grep httpd
發(fā)現(xiàn)
httpd_can_network_connect --> off
執(zhí)行下面命令之后
#setsebool httpd_can_network_connect 1
可以改為on的狀態(tài)
再次連接數(shù)據(jù)庫時(shí)可以正常使用了
但是等到系統(tǒng)重啟之后罪佳,發(fā)現(xiàn)同樣的錯(cuò)誤又出現(xiàn)了
于是我查看了SELinux的狀態(tài)
#/usr/sbin/sestatus -v
結(jié)果發(fā)現(xiàn)是
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
Process contexts:
Current context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Init context: system_u:system_r:init_t:s0
/usr/sbin/sshd system_u:system_r:sshd_t:s0-s0:c0.c1023
File contexts:
Controlling terminal: unconfined_u:object_r:user_devpts_t:s0
/etc/passwd system_u:object_r:passwd_file_t:s0
/etc/shadow system_u:object_r:shadow_t:s0
/bin/bash system_u:object_r:shell_exec_t:s0
/bin/login system_u:object_r:login_exec_t:s0
/bin/sh system_u:object_r:bin_t:s0 -> system_u:object_r:shell_exec_t:s0
/sbin/agetty system_u:object_r:getty_exec_t:s0
/sbin/init system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0
/usr/sbin/sshd system_u:object_r:sshd_exec_t:s0
發(fā)現(xiàn)SELinux是開啟的
只要我們編輯配置文件
#/etc/selinux/config
將SELINUX=enforcing改為SELINUX=disabled
之后再重啟,上面的錯(cuò)誤不會出現(xiàn)黑低,數(shù)據(jù)庫可以正常連接了