Redhat under PHP connection mysql, command line no problem, webpage error

Source: Internet
Author: User
Tags phpinfo
Redhat PHP connection to MySQL, the command line no problem, the page error.
Everyone help to see. I build php Apache MySQL environment on AWS.
Want to separate PHP Apache from MySQL.
Server A is only loaded with PHP and Apache. and the MySQL client
Server B only has MySQL installed.
The same code can execute successfully at the command line, and can query and insert data operations.
But there is an error under the webpage, prompt:

Can ' t connect to MySQL server on ' 192.168.9.9 ' (13)


The code is as follows:

PHP phpinfo ();

$link = mysql_connect ("192.168.9.9", "root", "12345") or Die ("can ' t connect MySQL". Mysql_error ());
mysql_select_db ("Wtest", $link) or Die (' can\ ' t use foo: '. mysql_error ());
$resx = mysql_query ("INSERT into West values (". Rand (0,9999). ")");
$res = mysql_query ("Show variables like ' socket '");
$res = mysql_query ("Select * from West");
Echo mysql_result ($res, 1);
while ($row =mysql_fetch_array ($res)) {
$return [] = $row;
echo $row [0]. "
\ n ";
}

?>


Everyone help to see. The MySQL server version must be installed on server A.

------Solution--------------------
is access restricted, and can only be accessed natively?
------Solution--------------------
Can a machine ping the B machine?
and is the B machine allowed to connect remotely?

------Solution--------------------
is MySQL extension on in phpinfo open properly?
------Solution--------------------
is the root account remote permission open?
------Solution--------------------
Assign the transport permission to a machine IP, for example:
GRANT select,insert,update,delete on *. * to root@ ' 172.16.16.152 ' identified by ' Youpassword ';
------Solution--------------------
It's OK to use the PHP command line on a machine, the database is on the B machine, so it's not a remote or permissions issue.

Seems to have encountered similar problems before, and Apache-related, do not remember how to solve the.
------Solution--------------------
Workaround 1: Setsebool-p httpd_can_network_connect_db=1

Workaround 2: Modify/etc/selinux/config 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.