Mysql_connect () does not work when apache starts; works from the command line

I have a strange problem. I am trying to write a simple php webpage on my server, but mysql_connect () does not connect to any server, local or other. Here where it is strange. If I take the same php script and run it from the command line, the script works. phpinfo () indicates that both the file (executed by apache) and the command line (executed as root) invoke the same php version, mysql loads, and php.ini the same.

In addition, I run the MediaWiki installation on the same server, and it uses the mysqld local area network and works fine, so I completely don’t understand why the code does not work. The error I get at runtime is:

Unable to connect to MySQL server on "xxx.xxx.xxx.xxx" (13)

(IP address is disabled for the privacy of the owner of the server I'm connecting to)

+3
source share
2 answers

What operating system are you trying to connect to? Looks like this could be a SELinux problem.

With SELinux, you can usually allow apache to make network connections with

/usr/sbin/setsebool httpd_can_network_connect 1

OR / usr / sbin / setsebool httpd_can_network_connect true

An operating system without SELinux may have a similar protection mechanism.

+3
source
  • Check your basic network connection. pingxxx.xxx.xxx.xxx from the web server. If this does not work, check the network configuration at both ends.
  • mysql -: mysql -h xxx.xxx.xxx.xxx -u user -p , : SELinux ( ) , , /etc/hosts? -v -v -v mysql.
  • , , mysql.
0

Source: https://habr.com/ru/post/1749526/


All Articles