In CentOS, php under httpd can connect to the mysql local machine, and 127.0.0.1 cannot be accessed.

Source: Internet
Author: User
The code you see in this article comes from www. cnblogs. comayanmwphp: $ server127.0.0.1; println (Begin); $ linkmysql_connect ($ server, mysql, mysql); if (! $ Link) {die (Couldnotconnect:. mysql_error (). mysql_errno ();}

The article you see from the http://www.cnblogs.com/ayanmw php code is very simple: $ server = "127.0.0.1"; println ("Begin"); $ link = mysql_connect ($ server, "mysql ", "mysql"); if (! $ Link) {die ('could not connect: '. mysql_error (). mysql_errno ();} enabled in linux

The article you see comes from http://www.cnblogs.com/ayanmw

Php code is simple:

$server="127.0.0.1";println("Begin");$link = mysql_connect($server,"mysql","mysql");if (!$link) {    die('Could not connect: ' . mysql_error().mysql_errno());}

In linux, you can use php mysql. php to view the running result, but an error is reported in my windows browser:

Cocould not connect: Can't connect to MySQL server on '2017. 0.0.1 '(13) 127


Cause:
# Getsebool-a | grep httpd
[Neo @ neo phpMyTest] $ getsebool-a | grep httpd

Httpd_can_network_connect --> off
Solution:
# Setsebool httpd_can_network_connect 1

It turns out to be SELINUX, so I usually disable SELINUX and iptables ip6tables directly.

# Disable SELINUXchkconfig -- level 12345 iptables offchkconfig -- level 12345 ip6tables offservice iptables stopservice ip6tables stop to view the SELinux status: 1./usr/sbin/sestatus-v # If The SELinux status parameter is enabled, SELinux status: enabled2 and getenforce # Can be used to check whether SELinux is disabled: 1. temporarily shut down (no need to restart the machine): setenforce 0 # Set SELinux to permissive mode # setenforce 1 Set SELinux to enforcing Mode 2. modify the configuration file and restart the machine: modify the/etc/selinux/config file and change SELINUX = enforcing to SELINUX = disabled.

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.