Reputation: 215
I am trying to connect a CRUD Simple with PHP, connecting a database in MySQL.
The problem is that in the mysql_connect function, in the host variable, if I pass the String localhost
, it connects and shows me the information of the database. The problem is when I put the IP of the host where the MySQL database is located, it shows me Permission denied.
I already send the privileges to the user carlos
with the following command:
GRANT ALL PRIVILEGES ON * . * TO 'carlos'@'%';
This is the connection code, the rest of the code does not affect, since this set are the first lines of the program:
$link = mysqli_connect("192.168.0.18:3306", "carlos", "abc123", "distribuidos") or die ('Error. ' . mysqli_connect_error());
With localhost, the connection work:
$link = mysqli_connect("localhost", "carlos", "abc123", "distribuidos") or die ('Error. ' . mysqli_connect_error());
It should be noted that I have also configured the firewall with the ports already open, in this case 3306
, and if I connect with the command mysql -u carlos -h 192.168.0.18 -p
from another machine connects me without problem.
I am using php 7.3 and CentOS 7.
SOLUTION
My solution is execute the next command on Linux: sudo setsebool -P httpd_can_network_connect 1
Upvotes: 0
Views: 1504
Reputation: 124
Three things you can check
or
or
sudo setsebool -P httpd_can_network_connect 1
Upvotes: 1