Support » Fixing WordPress » mysqli_real_connect(): (HY000/2002): Permission denied

  • Resolved jerryd221

    (@jerryd221)


    I just downloaded the latest version of wordpress onto AWS EC2 instance today and tried to install it but I cannot proceed as an error shown up on screen “Error establishing a database connection”. The error_log logged the following error:

    Warning: mysqli_real_connect(): (HY000/2002): Permission denied in /var/www/wordpress/wp-includes/wp-db.php on line 1452
    
    Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/wordpress/wp-includes/wp-db.php on line 1482
    
    Warning: mysql_connect(): Permission denied in /var/www/wordpress/wp-includes/wp-db.php on line 1482

    I have tried these two scripts directly on ec2 instance:

    // test1.php - old db driver(will be removed in php 7, which will be released soon)
    <?php
    $servername = "sample.rds.amazonaws.com:3306";
    $username = "mywordpress";
    $password = "mywordpress";
    
    $db = @mysql_connect($servername, $username, $password);
    if (!$db) echo "connection failed";
    else echo "connection succeeded";
    
    mysql_close($db);
    ?>

    and

    // test2.php - recommended db driver by mysql and php7
    <?php
    $servername = "sample.rds.amazonaws.com:3306";
    $username = "mywordpress";
    $password = "mywordpress";
    
    $mysqli = new mysqli($servername, $username, $password, 'mydb');
    
    /*
     * This is the "official" OO way to do it,
     * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
     */
    if ($mysqli->connect_error) {
        die('Connect Error (' . $mysqli->connect_errno . ') '
                . $mysqli->connect_error);
    }
    
    /*
     * Use this instead of $connect_error if you need to ensure
     * compatibility with PHP versions prior to 5.2.9 and 5.3.0.
     */
    if (mysqli_connect_error()) {
        die('Connect Error (' . mysqli_connect_errno() . ') '
                . mysqli_connect_error());
    }
    
    echo 'Success... ' . $mysqli->host_info . "\n";
    
    $mysqli->close();
    ?>

    both worked just fine. But once I go back to wordpress installation page(mysite.com/install.php), I always encountered same error.

    any ideas, guys? Please help…

    My server environment is:
    OS: CentOS 7 x86_64
    PHP: php 5.6 with php56_mysqlnd and php56w-fpm modules installed
    nginx: 1.8
    db: mysql 5.6 in AWS RDS

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jerryd221

    (@jerryd221)

    answer myself, problem solved. it was because of SELinux. By default it is enabled with enforcing specified. so I changed it to permissive, then done. if you have similar issue, then you can check SELinux with
    cat /etc/sysconfig/selinux and replaece SELINUX=enforcing with SELINUX=permissive

    Hi jerryd221,

    Is your issue resolved? I’m facing the same issue. Have tried a lot of things, not able to find a fix.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘mysqli_real_connect(): (HY000/2002): Permission denied’ is closed to new replies.