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