Php in redhat connects to mysql. there is no problem in the command line, and a webpage error occurs. Let's take a look. I set up a php apache mysql environment on AWS.
I want to separate php apache from mysql.
Server A only supports php and apache. And mysql client
Server B only installs mysql.
The same code can be successfully executed in the command line, queried, and inserted into data.
However, the following error occurs on the webpage:
Can't connect to MySQL server on '192.168.9.9' (13)
The code is as follows:
\n"; } ?>
Let's take a look. Is it necessary to install mysql server on server.
Reply to discussion (solution)
Is access permission restricted and only local access allowed?
I am a database server, a php server, and an apache server. It can only be used under the command line on the php and apache servers. But it won't work in the browser.
Can machine A be pinged to Machine B?
In addition, does the machine B allow remote connection?
Is mysql extension enabled normally in phpinfo?
Is the root account remote permission enabled?
Assign the operation permission to the ip address of machine a, for example:
GRANT select, insert, update, delete ON *. * TO root @ "172.16.16.152" identified by "youpassword ";
It is okay for people to use php command lines on machine A. The database is on Machine B, so it is not A remote or permission issue.
It seems that you have encountered a similar problem in the past, which is related to apache and cannot remember how to solve it.
Is there a problem with accessing this script on the apache web page in windows?
Thank you for your reply,
In windows, what does apache webpage access mean?
Because all the code is basic code, we just installed the server for testing.
So I feel that the code is okay. after all, there is no problem in the command line. Php does not seem to have a cross-platform problem.
The script on the command line is correct.
Is mysql extension enabled normally in phpinfo?
Expansion is normal. Phpinfo displays enabled.
Solution 1: setsebool-P httpd_can_network_connect_db = 1
Solution 2: modify/etc/selinux/config SELINUX = enforcing to SELINUX = disabled
Solution 1: setsebool-P httpd_can_network_connect_db = 1
Solution 2: modify/etc/selinux/config SELINUX = enforcing to SELINUX = disabled
Also try to modify my. cnf to add client part:
[Client]
Port = 3306
Socket =/var/lib/mysql. sock
Solution 1: setsebool-P httpd_can_network_connect_db = 1
Solution 2: modify/etc/selinux/config SELINUX = enforcing to SELINUX = disabled
Also try to modify my. cnf to add client part:
[Client]
Port = 3306
Socket =/var/lib/mysql. sock
Besides solution 1, the other two have tried. No, but after Solution 2 is modified, the machine cannot start... Solution 1 is fine ..