我无法从 php 建立数据库连接。建立数据库连接时出现 HTTP 500 内部服务器错误。我的 PHP 代码:
<?php
$servername = "localhost";
$username = "shudarsan";
$password = "shudarsan@localhost";
$database = "userInfo";
$conn = mysqli_connect($servername,$username,$password,$database);
if(!$conn) {
echo("Failed to connect to the database");
}else {
echo "Connection to the database was successfully made";
}
echo "hello there";
?>
https://i.stack.imgur.com/ox2F1.png
/var/log/nginx/error.log:
thrown in /var/www/php/projects/loginsys/partials/_dbConnect.php on line 6" while reading response header from upstream,
client: 127.0.0.1, server: php, request: "GET /projects/loginsys/partials/_dbConnect.php HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "php"
我能够从控制台(即mysql -u root -p
)建立 mysql 数据库连接,并且 mysql 用户 即 shudarsan 拥有数据库的所有权限。php 文件中的所有数据库信息都是正确的。当我运行 php 代码时,我在网页上收到 HTTP 500 内部服务器错误消息。