-1
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else {
echo "success";
}

when I am running this code on cli, I get the success message.

When I try this code from the browser, i.e run the index.php, I get permission denied error.

This is the VPS where I am doing it.

What could be the issue here?

nirvair
  • 4,001
  • 10
  • 51
  • 85

1 Answers1

0

Seems like your php file does not have enough rights to be executed try changing its rights with chmod

From the chmod man pages:

The chmod utility modifies the file mode bits of the listed files as specified by the mode operand. It may also be used to modify the Access Control Lists (ACLs) associated with the listed files.

SYNOPSIS
     chmod [-fv] [-R [-H | -L | -P]] mode file ...
     chmod [-fv] [-R [-H | -L | -P]] [-a | +a | =a] ACE file ...
     chmod [-fhv] [-R [-H | -L | -P]] [-E] file ...
     chmod [-fhv] [-R [-H | -L | -P]] [-C] file ...
     chmod [-fhv] [-R [-H | -L | -P]] [-N] file ...
Spangen
  • 4,420
  • 5
  • 37
  • 42
Skeec
  • 125
  • 9
  • This answer doesn't make sense because the code runs correctly from the cli without getting a `permission denied` error. – karel May 10 '19 at 06:14