LAMP Lab
Welcome to our hands-on lab where we embark on an exciting journey into the world of cloud computing, courtesy of Amazon Web Services (AWS). In this lab, we will walk you through the step-by-step process of setting up an EC2 instance, deploying a LAMP stack, and building a quick web application – all designed to calculate the coveted golden hour for photography enthusiasts.
​
​
​
Why AWS?
Amazon Web Services has redefined the landscape of cloud computing, offering a vast array of services that empower developers to create scalable and resilient applications. At the heart of this cloud ecosystem is the Elastic Compute Cloud (EC2), a service that allows you to launch virtual servers with unparalleled flexibility.
​
What's in Store for You?
-
Setting Up an EC2 Instance:
-
Dive into the essentials of EC2 as we guide you through the process of provisioning your virtual server in the AWS cloud.
-
Learn how to choose the right instance type, configure security settings, and launch your EC2 instance seamlessly.
-
-
Deploying a LAMP Stack:
-
Uncover the power of the LAMP stack – Linux, Apache, MySQL, and PHP/Python/Perl – as the backbone of dynamic web applications.
-
Follow our clear instructions to install and configure each component, creating a robust foundation for your web development journey.
-
-
Building a Web Application:
-
Take your newly minted LAMP stack for a spin by developing a quick web application.
-
In this lab, we focus on creating a simple yet effective tool to calculate the golden hour, a pivotal time for capturing stunning photography.
-
​
What to Expect:
-
Hands-On Experience: This lab is designed for hands-on learners. Get ready to dive into the AWS Management Console and witness the power of cloud computing firsthand.
-
Practical Insights: As you progress through the lab, you'll gain valuable insights into the seamless integration of AWS services, virtualization, and web application development.
-
Empowerment: By the end of this lab, you'll have the skills and confidence to stand up your EC2 instance, deploy a LAMP stack, and build a functional web application – all within the AWS ecosystem.
​
Are you ready to explore the limitless possibilities of cloud computing and bring your web development skills to new heights? Let's get started on this exciting journey together!
Go to the AWS website
Create Free Account
Learn more about AWS.
Enter your email address and name to create a free test account
Set Password, contact info, and credit card (this will not be charged), verify identity via text, then select the free support plan.
Launch EC2 Instance
Learn More about virtualization
​
Click go to AWS management console
Sign in as root user
Click in the top left on services
Select compute, then ec2
Click Launch Instance
Name it “Golden Hour Calculator”
Leave Defaults for OS, Architecture, and Instance Type
Click Generate New Keypair
Name it Keys, select RSA and .pem
Leave the rest defaults, and click launch
​
Connect to Your VM via SSH
Launch either command line or terminal (windows vs mac)
Type into the command line:
ssh -i Keys.pem ec2-user@[YOUR EC2 IP]
Cd Downloads
​
Chmod 400 “Keys.pem”
​
ssh -i Keys.pem ec2-user@[YOUR EC2 IP]
​
Install LAMP Stack
Learn More about LAMP stack
Update Linux
​
Sudo yum update
​
Install and Configure Apache
sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
sudo dnf install mariadb105-server
sudo systemctl start httpd
sudo systemctl enable httpd
Go to https://console.aws.amazon.com/ec2/ choose instances, select golden hour calculator, go to the security tab, click on your security group
Click edit inbound rules, enter type HTTP (Protocol should turn to TCP, Port SHould Turn to 80, Sources should still be custom and 0.0.0.0/0
Click Save Rule
Enter your IP address into your browser, you should see It Works!
Type:
​
sudo usermod -a -G apache ec2-user
Exit
ssh -i Keys.pem ec2-user@[YOUR EC2 IP]
Groups
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
​
Config Php
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
In your browser go to [YOUR EC2 IP]/phpinfo.php
​
Back in your command line, enter the following:
​
rm /var/www/html/phpinfo.php
​
Config Marina DB
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo dnf install php-mbstring php-xml -y
sudo systemctl restart httpd
sudo systemctl restart php-fpm
cd /var/www/html
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1
Preload Database
​
Go to YourIP/phpMyAdmin
Click SQL
​
Enter the following into a new SQL Query:
-- Create the database
CREATE DATABASE IF NOT EXISTS sunrise_data;
USE sunrise_data;
-- Create the table "sunrises"
CREATE TABLE IF NOT EXISTS sunrises (
id INT PRIMARY KEY AUTO_INCREMENT,
year INT NOT NULL,
month INT NOT NULL,
day INT NOT NULL,
sunrisetime TIME NOT NULL,
sunsettime TIME NOT NULL
);
-- Select the database
USE sunrise_data;
-- Insert the provided data into the "sunrises" table with TIME format
INSERT INTO sunrises (year, month, day, sunrisetime, sunsettime)
VALUES
(2024, 2, 26, '05:56:00', '17:25:00'),
(2024, 2, 27, '05:54:00', '17:27:00'),
(2024, 2, 28, '05:52:00', '17:28:00'),
(2024, 2, 29, '05:51:00', '17:29:00'),
(2024, 3, 1, '05:49:00', '17:31:00'),
(2024, 3, 2, '05:48:00', '17:32:00'),
(2024, 3, 3, '05:46:00', '17:33:00'),
(2024, 3, 4, '05:44:00', '17:34:00'),
(2024, 3, 5, '05:42:00', '17:36:00'),
(2024, 3, 6, '05:41:00', '17:37:00'),
(2024, 3, 7, '05:39:00', '17:38:00'),
(2024, 3, 8, '05:37:00', '17:39:00'),
(2024, 3, 9, '05:36:00', '17:41:00'),
(2024, 3, 10, '06:34:00', '18:42:00'),
(2024, 3, 11, '06:32:00', '18:43:00'),
(2024, 3, 12, '06:30:00', '18:44:00'),
(2024, 3, 13, '06:28:00', '18:46:00'),
(2024, 3, 14, '06:27:00', '18:47:00'),
(2024, 3, 15, '06:25:00', '18:48:00'),
(2024, 3, 16, '06:23:00', '18:49:00'),
(2024, 3, 17, '06:21:00', '18:50:00'),
(2024, 3, 18, '06:19:00', '18:52:00'),
(2024, 3, 19, '06:18:00', '18:53:00'),
(2024, 3, 20, '06:16:00', '18:54:00'),
(2024, 3, 21, '06:14:00', '18:55:00'),
(2024, 3, 22, '06:12:00', '18:56:00'),
(2024, 3, 23, '06:10:00', '18:58:00'),
(2024, 3, 24, '06:08:00', '18:59:00'),
(2024, 3, 25, '06:06:00', '19:00:00'),
(2024, 3, 26, '06:05:00', '19:01:00'),
(2024, 3, 27, '06:03:00', '19:02:00'),
(2024, 3, 28, '06:01:00', '19:04:00'),
(2024, 3, 29, '05:59:00', '19:05:00'),
(2024, 3, 30, '05:57:00', '19:06:00'),
(2024, 3, 31, '05:55:00', '19:07:00'),
(2024, 4, 1, '05:54:00', '19:08:00'),
(2024, 4, 2, '05:52:00', '19:09:00'),
(2024, 4, 3, '05:50:00', '19:11:00'),
(2024, 4, 4, '05:48:00', '19:12:00'),
(2024, 4, 5, '05:46:00', '19:13:00'),
(2024, 4, 6, '05:44:00', '19:14:00'),
(2024, 4, 7, '05:43:00', '19:15:00'),
(2024, 4, 8, '05:41:00', '19:17:00'),
(2024, 4, 9, '05:39:00', '19:18:00'),
(2024, 4, 10, '05:37:00', '19:19:00'),
(2024, 4, 11, '05:35:00', '19:20:00'),
(2024, 4, 12, '05:34:00', '19:21:00');
After, enter this into the query:
​
CREATE USER 'code_user'@'localhost' IDENTIFIED BY 'password';
Back in the command line, enter the following:
sudo mysql_secure_installation
No to everything except change password, create a root db password
Log in with it in your browser
Go to php admin IP/phpMyAdmin
Click User Accounts, check off select under permissions and click go
​
Create Webpage
Touch index.php
Nano index.php
​
Use the upcarrot key and x to save, select y to write to buffer and enter.
​
Enter [YOUR EC2 ID]/index.php into your browser, you should now see a farm.
Paste the context of the downloadable index.php into the terminal, and use the carrot key and x to exit, select y and enter to save
​
​
Copy and Paste
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sunrise, Sunset, and Golden Hour Times</title>
</head>
<body>
<h1>Sunrise, Sunset, and Golden Hour Times</h1>
<form method="post" action="">
<label for="year">Year:</label>
<input type="number" id="year" name="year" required min="1900" max="2300">
<label for="month">Month:</label>
<input type="number" id="month" name="month" required min="1" max="12">
<label for="day">Day:</label>
<input type="number" id="day" name="day" required min="1" max="31">
<button type="submit">Get Times</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve input values
$year = $_POST["year"];
$month = $_POST["month"];
$day = $_POST["day"];
// Perform database query (Replace with your database connection details)
$host = "localhost";
$username = "code_user";
$password = "password";
// $database = "sunrise_data";
$conn = mysqli_connect($host, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
echo "failed";
}
// Query for sunrise, sunset, and golden hour times
$query = "SELECT sunrisetime, sunsettime FROM sunrise_data.sunrises WHERE year = $year AND month = $month AND day = $day";
$result = mysqli_query($conn, $query);
if ($result) {
$row = mysqli_fetch_assoc($result);
$sunriseTime = $row['sunrisetime'];
$sunsetTime = $row['sunsettime'];
// Calculate golden hour times
$sunriseTimestamp = strtotime($sunriseTime);
$sunsetTimestamp = strtotime($sunsetTime);
$goldenHourStartMorning = date("h:i A", $sunriseTimestamp - 900);
$goldenHourEndMorning = date("h:i A", $sunriseTimestamp + 2700);
$goldenHourStartEvening = date("h:i A", $sunsetTimestamp - 2700);
$goldenHourEndEvening = date("h:i A", $sunsetTimestamp + 900);
// Display times
echo "<p>Sunrise Time: $sunriseTime</p>";
echo "<p>Sunset Time: $sunsetTime</p>";
echo "<p>Morning Golden Hour Start: $goldenHourStartMorning</p>";
echo "<p>Morning Golden Hour End: $goldenHourEndMorning</p>";
echo "<p>Evening Golden Hour Start: $goldenHourStartEvening</p>";
echo "<p>Evening Golden Hour End: $goldenHourEndEvening</p>";
} else {
echo "Error querying the database: " . mysqli_error($conn);
}
// Close the database connection
mysqli_close($conn);
}
?>
</body>
</html>