E-commerce App local deploy issue

Hello everyone,

So I’ve decided to do the 2 tier Application at the end of the pre-requisite course… locally on my own laptop. I made my own github repo with the forked e-commerce app (I hope it’s fine) and then I decided to test my VM knowledge as well and do the whole thing inside a CentOS9 VM with Vagrant and Virtual Box from my Ubuntu host. I know it doesn’t really make sense but I wanted to get to know the process of using VMs.

So I ssh’d with my vscode from my ubuntu host to the centos VM successfully and then followed all the steps to deploy the e-commerce app. Everything went smoothly up until the very bitter end when I curl localhost from my terminal and got greeted with a lot of gibberish symbols and a long html page from which an important bit I gathered was this part:

This page is used to test the proper operation of the HTTP server after it has been installed. If you can read this page it means that this site is working properly. This server is powered by CentOS.

I checked it and saw that this is some sort of Apache test page. But I wanted to open the e-commerce home page from the labs in my browser… I tried of course manually typing the localhost page in the browser but it didn’t work. I’ve put a lot of effort into doing all this and I hoped to see a good final result.

Any insights and help would be greatly appreciated!

Thank you!
Plamen Dimitrov

If you ae seeing the Apache test page, then it is likely that you have not configured the Apache server correctly.
You need to set the index page to index.php and then restart the Apache server.

DevOps Pre-Requisite Course | KodeKloud from 11:00

Unfortunately I’ve already changed it to index.php with the same result.

IfModule dir_module>
DirectoryIndex index.php
/IfModule>

I restarted the service afterwards as well.

I saw this article that says:

So how can I make the Apache test page go away?

Simply open your /var/www/index.html file and modify it or delete file (though it might trigger new error). Under Red Hat Enterprise Linux/CentOS/Fedora Core, rename or delete a file /etc/httpd/conf.d/welcome.conf to make sure you do not see Apache test page.

I proceeded to delete the welcome.conf and after i curl localhost all I see is another html in my terminal:

DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2 Final//EN”>
html>
head>
title>Index of /
head>
body>
h1>Index of /
ul>

Very strange.

Works fine for me. I did it on a KodeKloud centos playground, but any centos VM will work the same

In /etc/httpd/conf/httpd.conf - which exists after yum install httpd

image

In /var/www/html/index.php - which exists after git clone

This script if pasted into the command prompt of a newly built centos VM should build the whole thing. It simply combines all the code elements of the github page.

{
# Install all the packages we will need with a single yum command
sudo yum install -y firewalld mariadb-server httpd php php-mysqlnd git

# Start firewall
sudo systemctl start firewalld
sudo systemctl enable firewalld

# Configure firewall for mariadb
sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
sudo firewall-cmd --reload

# Start mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

# Wait for it to be fully running
sleep 5

# SQL Script to set up user and database
cat > db-load-script.sql <<-EOF
CREATE DATABASE ecomdb;
CREATE USER 'ecomuser'@'localhost' IDENTIFIED BY 'ecompassword';
GRANT ALL PRIVILEGES ON *.* TO 'ecomuser'@'localhost';
FLUSH PRIVILEGES;
USE ecomdb;
CREATE TABLE products (id mediumint(8) unsigned NOT NULL auto_increment,Name varchar(255) default NULL,Price varchar(255) default NULL, ImageUrl varchar(255) default NULL,PRIMARY KEY (id)) AUTO_INCREMENT=1;
INSERT INTO products (Name,Price,ImageUrl) VALUES ("Laptop","100","c-1.png"),("Drone","200","c-2.png"),("VR","300","c-3.png"),("Tablet","50","c-5.png"),("Watch","90","c-6.png"),("Phone Covers","20","c-7.png"),("Phone","80","c-8.png"),("Laptop","150","c-4.png");
EOF

# Apply SQL script
sudo mysql < db-load-script.sql

# Set up firewall for apache
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --reload

# Configure apache
sudo sed -i 's/index.html/index.php/g' /etc/httpd/conf/httpd.conf

# Start apache
sudo systemctl start httpd
sudo systemctl enable httpd

# Clone repo containing PHP script to web directory
sudo git clone https://github.com/kodekloudhub/learning-app-ecommerce.git /var/www/html/

# Configure PHP script to connect to mariadb on localhost
sudo sed -i 's/172.20.1.101/localhost/g' /var/www/html/index.php
}

Now it’s running, test it.