Can't connect to MySQL server on 'XX.XX.XX.XX' (13)

August 11, 2018 1.7k views
MySQL Nginx CentOS

Hello dear experts!!!

Need help!

CentOS+MarisDB+PHP+Nginx

Have a test table in DB, that contain tow strings:
'qwe','asd'
'rty','fgh'

Have a test script, that works if I lounch it from cmd:

$ php test.php
<html><header></header><body>test page<br>qwe - asd
<br>
rty - fgh
<br>
</body></html>

So, MySQL+PHP works!!!

Have info.php file in the root dir of nginx, that works too (I see page in browser).
So, Nginx+PHP works too!!!

But, when I request test.php by http, browser (and curl too) returns that:
Can't connect to MySQL server on 'XX.XX.XX.XX' (13)

I have installed LEMP twice with the same result by using this instruction: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

Several hours in internet didn't provide any answers!
Thanks for help!

1 comment
  • P.S.
    If someone would like to test, here are scripts:

    ---------
    create table a_first (request varchar(30), answer varchar(30)) ;
    insert into a_first values ('qwe','asd') ;
    insert into a_first values ('rty','fgh') ;
    ---------
    
    /usr/share/php/db.php
    $servername="ip_address";
    $username="mmysql_user";
    $password="mysql_pass";
    $dbname="dbname" ;
    
    ---------
    <?php
    echo "<html><header></header><body>";
    require_once 'db.php';
    
    echo "test page" ;
    echo "<br>" ;
    
    // Create connection
    $conn = mysql_connect($servername, $username, $password);
    
    if (!$conn) {
        die('cani\'t connect: ' . mysql_error());
    }
    
    $db_selected = mysql_select_db($dbname, $conn);
    if (!$db_selected) {
        die ('can\'t select DB: ' . mysql_error());
    }
    
    $sql = "select * from a_first; " ;
    $result = mysql_query($sql);
    
    if (!$result) {
        die('SQL error: ' . mysql_error());
    }
    
    while ($row = mysql_fetch_assoc($result)) {
        echo $row['request']." - ".$row['answer']." \n";
        echo "<br>\n" ;
    }
    
    mysql_free_result($result);
    
    echo "</body></html>";
    ?>
    
1 Answer

setsebool -P httpdcannetworkconnectdb 1

Have another answer? Share your knowledge.