简体   繁体   中英

PHP - Cannot connect to mysql on aws ec2

I am able to connect to the mysql server from the terminal on my local system but cannot connect to it from my php code.

<!-- Establish conenction to sql -->
<?php

session_start();

$servername = "ec2-xxxx.compute-1.amazonaws.com";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection, the code hangs on this line
$conn = new mysqli($servername, $username, $password, $dbname);

?>

The code seems to hang on the 'new sqli' line. I tried placing it inside a try-catch block, but the catch block is never executed. Nothing gets executed beyond that line.

Edit: Dipti suggest that I place ini_set('display_errors', 1); on top on the php file. This gave me an output saying that mysqli couldn't be found. Doing a "sudo apt install php-mysql" fixed the issue.

您使用sql server连接,并且server name应为localhost而不是Amazon链接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM