I’m new to AWS and I’ve tried deploying my web application but keep getting 504 Gate-way Timeout
. However, after a bit of debugging and redeploying, I noticed that this was being caused by the PHP segment of my index.php file:
<?php $dsn = 'mysql:host=<AWS database hostname>; dbname=e-flash-card-schema'; $username = '<username>'; $password = '<password>'; $db = new PDO($dsn, $username, $password); session_start(); $user = @$_SESSION['Username']; $card_number = @$_SESSION['Card_number']; $query1 = "SELECT Front_Text FROM `e-flash-card-schema`.`card_text` WHERE Username = '$user' AND Card_Number = '$card_number'"; $statement1 = $db->prepare($query1); $statement1->execute(); $front_text = $statement1->fetch(); $statement1->closeCursor(); $query2 = "SELECT Back_Text FROM `e-flash-card-schema`.`card_text` WHERE Username = '$user' AND Card_Number = '$card_number'"; $statement2 = $db->prepare($query2); $statement2->execute(); $back_text = $statement2->fetch(); $statement2->closeCursor(); ?>
In particular when I removed everything before the session_start();
line, the webpage was able to load, although it was with errors that I’m assuming were caused by the lines $query1 = ...
and below. This led me to believe that there’s some error caused by my attempt to connect to the database
When I run the same code using XAMPP connecting to the same AWS database server on my machine, everything works fine. Does anyone know what might be causing this?
I’m also using the MariaDB engine for the AWS database and Elastic Beanstalk to deploy my web application if that helps.
Edit: If anyone is looking at this question, could it be because cannot handle this type of thing?
Advertisement
Answer
I finally managed to get it working by creating a snapshot of the original AWS RDB and configuring my elastic beanstalk database using that snapshot. I then connected to that database instead using the elastic beanstalk database hostname in my PHP code where the original RDB hostname was.
In summary, I wasn’t able to connect to the external databse, so I copied that database into my elastic beanstalk configuration and used that instead.
Hope this helps anyone having that might be having the same issue