Garnica1999
Garnica1999

Reputation: 215

Problem of Denied Permissions in connection between PHP and MYSQL

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

Answers (1)

snfrox
snfrox

Reputation: 124

Three things you can check

  1. Please check your port is open or not

or

  1. Remove bind-address 127.0.0.1 in /etc/mysql/my.cnf

or

  1. apache is not configured for external access. try sudo setsebool -P httpd_can_network_connect 1

Upvotes: 1

Related Questions