CentOS PHP using 127.0.0.1 can not connect to MySQL solution

Source: Internet
Author: User
Tags php code php mysql centos iptables

The PHP code is simple:

The

code is as follows:


$server = "127.0.0.1";


println ("Begin");


$link = mysql_connect ($server, "MySQL", "MySQL");


if (! $link) {


die (' Could not connect: '. Mysql_error (). Mysql_errno ());


}

Linux native use of PHP mysql.php can view the results of the run, but in my Windows browser error:

The

code is as follows:


could not Connect:can ' t connect to MySQL server on ' 127.0.0.1 ' (13) 2003

Reason:

The

code is as follows:


#getsebool-A | grep httpd


[Neo@neo phpmytest]$ getsebool-a | grep httpd


Found Httpd_can_network_connect--> off
Solution:

The

code is as follows:


#setsebool httpd_can_network_connect 1

It turned out to be SELINUX, so I generally shut down SELINUX and iptables ip6tables directly.

The

code is as follows:


# Close SELinux


chkconfig--level 12345 iptables off

Chkconfig--level 12345 ip6tables off

Service Iptables Stop

Service Ip6tables Stop


To view the SELinux status:

1,/usr/sbin/sestatus-v # #如果SELinux Status parameter is enabled that is open

SELinux status:enabled

2, Getenforce # #也可以用这个命令检查

Close SELinux:

1, temporarily shut down (do not restart the machine):

Setenforce 0 # #设置SELinux become permissive mode

# #setenforce 1 set SELinux become enforcing mode

2, modify the configuration file needs to reboot the machine:

modifying/etc/selinux/config files

Change Selinux=enforcing to Selinux=disabled

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.