This guide explains how to deploy the KodeKloud e-commerce application on a CentOS machine, covering prerequisites, database setup, and web application deployment.
In this guide, you’ll learn how to deploy the KodeKloud e-commerce application on a CentOS machine. The application code is hosted on GitHub under the repository “learning-app-ecommerce” at the KodeKloud hub. The repository includes all the necessary files along with a detailed README for further instructions.Below is a step-by-step guide covering prerequisites installation, database and firewall configuration, and finally, the deployment of the web application.
First, install and configure the firewall (firewalld) so that it automatically starts on system boot. This ensures that your system rules are applied correctly, aiding in troubleshooting any future issues.
The default configuration file (/etc/my.cnf) appears as follows:
Copy
Ask AI
# This group is read both by the client and the server[client-server]# include all files from the config directory!includedir /etc/my.cnf.d
If you need to change settings like the MySQL port or adjust other configurations, update this file as required. For this demo, default settings are maintained.
Follow these steps to configure MariaDB for the e-commerce application:
Create the database.
Create a new user with appropriate privileges.
Load sample inventory data.
Log in to the MariaDB console:
Copy
Ask AI
sudo mysql
Create the database and verify its creation:
Copy
Ask AI
CREATE DATABASE ecomdb;SHOW DATABASES;
You should see “ecomdb” listed alongside default databases like information_schema, mysql, and performance_schema.Now, create a new user and grant it privileges:
Copy
Ask AI
CREATE USER 'ecomuser'@'localhost' IDENTIFIED BY 'ecompassword';GRANT ALL PRIVILEGES ON *.* TO 'ecomuser'@'localhost';FLUSH PRIVILEGES;
To populate the ecomdb database with sample data, create a SQL script (for example, named db-load-script.sql). You can either copy the script from the GitHub repository’s assets or create it manually:
Copy
Ask AI
cat > db-load-script.sql <<-EOFUSE 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");EOF
Load the SQL script into MySQL with:
Copy
Ask AI
mysql < db-load-script.sql
Verify that the inventory data has been imported by executing the following commands in the MariaDB console:
After saving any changes, refresh your browser to see the updated product listing.
By following these steps, you have successfully deployed and configured the KodeKloud e-commerce application on a CentOS machine. Both the database and web server are now running and properly connected.