在虚拟机里部署prestashop,遇到mysql数据库无法连接的问题。虚拟机为webserver需要连接数据,数据库安装在主机上,虚拟机通过bridge方式连网。
检查mysql配置bind-access、skip-networking均未开启,[client]已经配置,root用户允许远程host访问;数据库主机的防火墙开启,但是允许3306端口访问。
问题表现如下
1.通过Mysql客户端可以连接数据库,即mysql -h *.*.*.* -u root -p
2.通过phpmyadmin无法连接数据库,无论是tcp还是socket方式
3.通过mysql_connect()函数也无法连接数据,得到错误信息:SQLSTATE[HY000] [2003] Can't connect to MySQL server on '*.*.*.*' (13)
最终解决方法
检查selinux的设置发现,httpd_can_network_connect为off,很容易理解,通过httpd不能进行网络连接,因此,mysql_connect()函数报错。如下:
$getsebool -a | grep httpd
allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_read_user_content --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
修改方法:setsebool httpd_can_network_connect 1
(责任编辑:最模板) |