Project: Securely Storing Login Information - AWS-RDS

Steps:
Create EC2-Instance - Myinstance
Create RDS Database - database
Install Nginx, Mariadb and Php
sudo yum install https
sudo yum install nginx -y
sudo dnf install php -y
sudo yum install maraidb105-server -y
- Restart nginx, mariadb, php

- Inside html folder write index.php file and check it is working or not

<?php echo "php is running"; ?>Check page is working or not: IP-Address/index.php

After that write a index.php file and submit.php file
💡Make sure in submit.php file you write the servername,username, password, databasename as what you created.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login</title> <style> body { font-family: Arial, sans-serif; } .container { width: 300px; margin: 0 auto; padding: 20px; border: 1px solid #ccc; border-radius: 5px; background-color: #f9f9f9; } .container h2 { text-align: center; } .container input[type="text"], .container input[type="password"] { width: 100%; padding: 10px; margin: 8px 0; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } .container input[type="submit"] { width: 100%; background-color: #4CAF50; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; } .container input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>Login</h2> <form action="submit.php" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username" required> <label for="password">Password:</label> <input type="password" id="password" name="password" required> <input type="submit" value="Login"> </form> </div> </body> </html><?php // Check if form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Retrieve form data $username = $_POST["username"]; $password = $_POST["password"]; // Database connection details $servername = "your_RDS_end_point"; // Replace with your database hostname as RDS end point $username_db = "admin"; // Replace with your database username $password_db = "password1234"; // Replace with your database password $dbname = "mydatabase"; // Replace with your database name // Create connection $conn = new mysqli($servername, $username_db, $password_db, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // SQL query to insert data into the table $sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } // Close connection $conn->close(); } ?>

Now Connect RDS
💡Make sure you EC2 and RDS are connected
sudo mysql -h end-point-of-RDS -u admin -p --enter your database password --create database create database mydatabase; use mydatabase;Then create table eg: posts

create table posts(id int primary key not null auto_increment, email varchar (200),password varchar(200));Open the Browser and test the login form

You will get the message "New record created successfully"

Now check if data is inserted into RDS or not
select * from posts;You will see the inserted data information into Mysql

By following these steps, you should have a basic login system set up where user login information is stored in an RDS database.


