Connect DATABASE Error TYPE: 2002: Permission denied
<p>I am trying to connect the database with the following script(cxn-test.php)</p>

<pre><code>&lt;?php
$host = '155.30.136.20';//dummy ip 
$user = 'abc_user';
$pass = 'xxxxxxxxx';
$dbname = 'welcome';
$link = mysqli_connect($host, $user, $pass,$dbname);
if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}else {
    echo "success" . PHP_EOL;
}
</code></pre>

<p>When I am trying on the terminal </p>

<blockquote>
  <p>php cxn-test.php //success</p>
</blockquote>

<p>But when I am trying on localhost i am getting the following error,</p>

<blockquote>
  <p>curl -s <a href="http://localhost/cxn-test.php" rel="noreferrer">http://localhost/cxn-test.php</a></p>
</blockquote>

<p><code>Error: Unable to connect to MySQL.
Debugging errno: 2002
Debugging error: Permission denied</code></p>

<p>This is strange issue it's not working on the localhost but working good on command line. </p>