0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

12 Comments

is this your mysql server ip address. if so it's wrong, you can either put 0.0.0.0 to allow any network or the sub net address to specifically give access to a network
read this for more details about bind address stackoverflow.com/questions/3552680/…
Now change the IP to 0.0.0.0, But still with the same error, I do not know what to do anymore
did you restart the service?
Yes, i restart the mysqld and httpd services, but the mysql connection not work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.