kodekloudhub/learning-app-ecommerce
Fork: 1115 Star: 322 (更新于 2024-12-02 16:12:05)
license: 暂无
Language: SCSS .
A sample e-commerce learning app
Introduction
This is a sample e-commerce application built for learning purposes.
Here's how to deploy it on CentOS systems:
Deploy Pre-Requisites
- Install FirewallD
sudo yum install -y firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo systemctl status firewalld
Deploy and Configure Database
- Install MariaDB
sudo yum install -y mariadb-server
sudo vi /etc/my.cnf
sudo systemctl start mariadb
sudo systemctl enable mariadb
- Configure firewall for Database
sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
sudo firewall-cmd --reload
- Configure Database
$ mysql
MariaDB > CREATE DATABASE ecomdb;
MariaDB > CREATE USER 'ecomuser'@'localhost' IDENTIFIED BY 'ecompassword';
MariaDB > GRANT ALL PRIVILEGES ON *.* TO 'ecomuser'@'localhost';
MariaDB > FLUSH PRIVILEGES;
ON a multi-node setup remember to provide the IP address of the web server here:
'ecomuser'@'web-server-ip'
- Load Product Inventory Information to database
Create the db-load-script.sql
cat > db-load-script.sql <<-EOF
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
Run sql script
sudo mysql < db-load-script.sql
Deploy and Configure Web
- Install required packages
sudo yum install -y httpd php php-mysqlnd
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --reload
- Configure httpd
Change DirectoryIndex index.html
to DirectoryIndex index.php
to make the php page the default page
sudo sed -i 's/index.html/index.php/g' /etc/httpd/conf/httpd.conf
- Start httpd
sudo systemctl start httpd
sudo systemctl enable httpd
- Download code
sudo yum install -y git
sudo git clone https://github.com/kodekloudhub/learning-app-ecommerce.git /var/www/html/
-
Create and Configure the
.env
FileCreate an
.env
file in the root of your project folder.cat > /var/www/html/.env <<-EOF DB_HOST=localhost DB_USER=ecomuser DB_PASSWORD=ecompassword DB_NAME=ecomdb EOF
-
Update
index.php
Update the
index.php
file to load the environment variables from the.env
file and use them to connect to the database.<?php // Function to load environment variables from a .env file function loadEnv($path) { if (!file_exists($path)) { return false; } $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { if (strpos(trim($line), '#') === 0) { continue; } list($name, $value) = explode('=', $line, 2); $name = trim($name); $value = trim($value); putenv(sprintf('%s=%s', $name, $value)); } return true; } // Load environment variables from .env file loadEnv(__DIR__ . '/.env'); // Retrieve the database connection details from environment variables $dbHost = getenv('DB_HOST'); $dbUser = getenv('DB_USER'); $dbPassword = getenv('DB_PASSWORD'); $dbName = getenv('DB_NAME'); ?> ON a multi-node setup, remember to provide the IP address of the database server in the .env file.
-
Test
curl http://localhost
最近版本更新:(数据更新于 1970-01-01 00:00:00)
kodekloudhub/learning-app-ecommerce同语言 SCSS最近更新仓库
2023-03-22 19:42:52 Sansui233/logseq-bonofix-theme
2023-01-10 15:41:26 creativetimofficial/vue-light-bootstrap-dashboard
2021-01-03 03:40:41 mxdi9i7/vant-react
2016-05-11 16:23:31 Gaohaoyang/gaohaoyang.github.io
1970-01-01 00:00:00 microsoft/TypeScript-Node-Starter
1970-01-01 00:00:00 Cyber-Security-Hub/cyber-security-hub.github.io