This is a Laravel-based e-commerce application using PostgreSQL as the database and Docker containers for easy setup. It includes features like a shopping cart, product filtering, AI-powered recommendations, and more. This guide explains how to configure, execute, and test the program.
- Prerequisites
- Configuration
- Setting Up Docker Containers
- Running the Application
- Running CI/CD Tests
- Troubleshooting
Ensure you have the following installed on your system:
-
Docker and Docker Compose:
-
Composer:
-
Node.js (for frontend assets):
-
PostgreSQL (Optional):
- Required only if you are not using the Dockerized PostgreSQL instance.
Clone this repository to your local machine:
git clone https://github.com/your-username/ecommerce-app.git
cd ecommerce-app
Copy the .env.example
file and configure your environment variables:
cp .env.example .env
-
Database Configuration (for Dockerized PostgreSQL):
DB_CONNECTION=pgsql DB_HOST=db DB_PORT=5432 DB_DATABASE=ecommerce_php DB_USERNAME=postgres DB_PASSWORD=your_password
-
App Configuration:
- Set
APP_URL
to match your local setup (e.g.,http://localhost
).
APP_URL=http://localhost
- Set
-
Queue and Cache: Configure cache drivers as needed (default is fine):
CACHE_DRIVER=file QUEUE_CONNECTION=sync
-
Stripe or Payment API Keys (Optional): Add keys if you’re integrating payments.
Ensure docker-compose.yml
is properly configured. The default file includes:
- App container for Laravel.
- Database container for PostgreSQL.
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www
ports:
- "8000:8000"
depends_on:
- db
environment:
DB_HOST: db
DB_PORT: 5432
DB_DATABASE: ecommerce_php
DB_USERNAME: postgres
DB_PASSWORD: your_password
db:
image: postgres:13
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: your_password
POSTGRES_DB: ecommerce_php
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
Run the following command to build and start the containers:
docker-compose up --build
This will:
- Build the Laravel app container.
- Start the PostgreSQL database container.
- Laravel App: Access the app at http://localhost:8000.
- PostgreSQL:
- Connect using a tool like pgAdmin with these credentials:
- Host:
localhost
- Port:
5432
- Database:
ecommerce_php
- Username:
postgres
- Password:
your_password
- Host:
- Connect using a tool like pgAdmin with these credentials:
Run the following commands inside the app
container:
docker exec -it ecommerce-app bash
composer install
npm install && npm run dev
Run the following commands to set up the database schema and seed initial data:
php artisan migrate
php artisan db:seed
Inside the app container, execute:
php artisan test
This will run unit and feature tests defined in the tests/
directory.
The project includes a GitHub Actions workflow for CI/CD:
name: Laravel CI/CD
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: mbstring, pdo_pgsql
- name: Install Dependencies
run: composer install
- name: Run Tests
run: php artisan test
-
Push to the
main
branch:git add . git commit -m "Add feature X" git push origin main
-
Check GitHub Actions in your repository to ensure the CI workflow is successful.
-
Database Connection Error:
- Ensure
docker-compose
is running. - Verify
.env
matches the database credentials. - Clear Laravel cache:
php artisan config:clear php artisan cache:clear
- Ensure
-
Node.js Not Installed: Install Node.js and rerun
npm install && npm run dev
. -
Docker Errors:
- Restart Docker services:
docker-compose down docker-compose up --build
- Restart Docker services:
-
CI/CD Fails:
- Check GitHub Actions logs for specific errors.
- Ensure all dependencies are installed correctly.
- Local Development: Use
APP_ENV=local
for development. - Production Deployment: Consider using a cloud service (e.g., AWS, DigitalOcean) and securing the app with SSL via Cloudflare.