5

On my webpage I'm using PHP and I run it in Ubuntu 16.04.

It works well.

Then I try to run it on CentOS 5.11 (I know centOS 5.11 is out of date, but for many reasons I must I use it).

And the result is my webpage doesn't work.

I show this error:

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Permission denied' in /var/www/html/IPU-GUI/website2/templates/sql_login.php:3 Stack trace: #0 /var/www/html/IPU-GUI/website2/templates/sql_login.php(3): mysqli_connect('127.0.0.1', 'root', '123456', 'ipu1') #1 /var/www/html/IPU-GUI/website2/sip.php(30): require_once('/var/www/html/I...') #2 {main} thrown in /var/www/html/IPU-GUI/website2/templates/sql_login.php on line 3

enter image description here

Here is my code:

<?php
require '../functions/server_info.php';
$conn = mysqli_connect($sql_login["host"], $sql_login["username"], $sql_login["password"], $sql_db);
if (!$conn) {
    echo mysqli_connect_error();
}

?>

And server_info.php

$sql_login = array(
"host"=>"127.0.0.1", 
"port"=>"3306", 
"username"=>"root",
"password"=>"123456" 
);
$sql_db = "ipu1"; 

UPDATE: I try to fix this error by change "host"=>"127.0.0.1" to "host"=>"localhost" it works. But I don't know what wrong? What different from "127.0.0.1" and "localhost".

mx0
  • 4,605
  • 10
  • 39
  • 47
  • Possible duplicate of [Access denied for user 'root'@'localhost' while attempting to grant privileges. How do I grant privileges?](https://stackoverflow.com/questions/8484722/access-denied-for-user-rootlocalhost-while-attempting-to-grant-privileges) – Kacper Polak Sep 08 '17 at 09:28
  • Please copy and paste the error instead of having it in a picture. – Clíodhna Sep 08 '17 at 09:32
  • @Clíodhna: I have both in my question. I post again for you: Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Permission denied' in /var/www/html/IPU-GUI/website2/templates/sql_login.php:3 Stack trace: #0 /var/www/html/IPU-GUI/website2/templates/sql_login.php(3): mysqli_connect('127.0.0.1', 'root', '123456', 'ipu1') #1 /var/www/html/IPU-GUI/website2/sip.php(30): require_once('/var/www/html/I...') #2 {main} thrown in /var/www/html/IPU-GUI/website2/templates/sql_login.php on line 3 –  Sep 08 '17 at 09:34

0 Answers0