skip to Main Content

This is not about ‘localhost’. Both the command line version of ‘mysql’ as well as a script I wrote in Perl (using perl-DBD-MySQL) can login, get to this database and work with it. Only PHP gives the permission denied error, and that error is not reported in any of the various log files. I even went as far as creating a simple test user in the database to avoid any issues with special characters in the password:

create user ‘web’@’%’ identified by ‘Iamnotarobot’;

and again the command line can login with this credential but PHP says permission denied.

I don’t know what is throwing the error so I can’t address it. I’m literally lost.
Relevant info:
RHEL 8 = 4.18.0
php 7.2.11
nginx 1.14.1

And here’s the actual code that’s failing:

<?php
$host="core";
$user="web";
$pass="Iamnotarobot";
$db="mydb";

$conn = new mysqli($host,$user,$pass,$db);
if( $conn->connect_errno ) {
  exit($conn->connect_errno);
}
?>

2

Answers


  1. Chosen as BEST ANSWER

    It turned out to be an selinux issue. Here's how I fixed it:

    setsebool -P httpd_can_network_connect_db 1
    

    Now with setenforce back to '1', the page can connect to the database.


  2. Check with php-mysql package installation.

    If perl can connect remotely and php could not…the issue is with php-mysql installation only.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search