A full-stack product listing and management system built with Docker, Apache/PHP, MySQL, Express.js API, and vanilla JavaScript frontend. This project demonstrates a complete web application setup using containerization and modern web technologies.
This is a teaching lab project that showcases:
- Docker containerization with Apache, MySQL, and phpMyAdmin
- RESTful API built with Express.js and Node.js
- MySQL database for data persistence
- Responsive frontend with vanilla HTML, CSS, and JavaScript
- CRUD operations for product management
lab-setup-product-shop-web/
├── docker-compose.yml # Docker services configuration
├── apache/
│ └── vhosts/
│ └── myshop.local.conf # Apache virtual host configuration
├── api/
│ └── product-apis/ # Express.js REST API
│ ├── server.js # Main API server
│ ├── db.js # Database connection
│ ├── seeder.js # Database seeder script
│ ├── package.json # Node.js dependencies
│ └── README.md # API documentation
├── htdocs/
│ └── myshop.local/
│ └── index.html # Frontend application
└── mysql/
└── data/ # MySQL data directory (auto-generated)
Before you begin, ensure you have the following installed on your system:
- Docker Desktop for Windows (version 4.0 or higher)
- Node.js (version 14 or higher)
- Git for Windows (optional, for cloning)
- Docker Desktop for Mac (version 4.0 or higher)
- Node.js (version 14 or higher)
- Git (pre-installed on macOS)
Option A: Using Git
git clone <repository-url>
cd lab-setup-product-shop-webOption B: Download ZIP
- Download and extract the project to your preferred location
Make sure Docker Desktop is running, then open a terminal/command prompt in the project root directory.
For Mac/Linux:
docker-compose up -dFor Windows (Command Prompt):
docker-compose up -dFor Windows (PowerShell):
docker-compose up -dThis command will start three Docker containers:
- Apache/PHP (port 80) - Web server
- MySQL (port 3306) - Database server
- phpMyAdmin (port 8081) - Database management interface
Wait for all containers to start (usually takes 30-60 seconds on first run).
Navigate to the API directory and install the required packages:
For Mac/Linux:
cd api/product-apis
npm installFor Windows:
cd api\product-apis
npm installCreate the database and populate it with sample products:
npm run seedYou should see a success message indicating that the database has been initialized with sample products.
Start the Express.js API server:
For development (with auto-reload):
npm run devFor production:
npm startThe API server will start on http://localhost:3000
Open your web browser and navigate to:
- Frontend Application: http://localhost or http://myshop.local
- API Documentation: http://localhost:3000/api/health
- phpMyAdmin: http://localhost:8081
- Username:
root - Password:
root
- Username:
The web interface provides:
- Browse all products in a responsive grid layout
- Search products by name or description
- Filter products by category
- View detailed product information
- Responsive design for mobile and desktop
GET /api/products- Get all products- Query parameters:
?search=keywordor?category=CategoryName
- Query parameters:
GET /api/products/:id- Get a single product by IDPOST /api/products- Create a new productPUT /api/products/:id- Update a productDELETE /api/products/:id- Delete a product
GET /api/categories- Get all unique categories
GET /api/health- Check API status
Get all products:
curl http://localhost:3000/api/productsSearch products:
curl http://localhost:3000/api/products?search=laptopFilter by category:
curl http://localhost:3000/api/products?category=ElectronicsThe MySQL database is configured with the following credentials (defined in docker-compose.yml):
Host: localhost
Port: 3306
Database: app
Username: app
Password: secret
Root Password: root
The API can be configured using environment variables. Create a .env file in the api/product-apis directory:
PORT=3000
DB_HOST=localhost
DB_USER=app
DB_PASSWORD=secret
DB_NAME=app
DB_PORT=3306If you encounter port conflicts:
Windows:
# Check what's using port 80
netstat -ano | findstr :80
# Check what's using port 3306
netstat -ano | findstr :3306Mac/Linux:
# Check what's using port 80
lsof -i :80
# Check what's using port 3306
lsof -i :3306Solution: Stop the conflicting service or modify the port in docker-compose.yml
- Ensure Docker Desktop is running
- Check Docker Desktop for any errors
- Try restarting Docker Desktop
-
Verify Docker containers are running:
docker ps
-
Check MySQL is ready:
docker logs mysql_db
-
Ensure the database is seeded:
cd api/product-apis npm run seed
If you encounter dependency issues:
cd api/product-apis
rm -rf node_modules package-lock.json
npm installTo stop all services:
- Stop the Node.js API server (Ctrl+C in the terminal)
- Stop Docker containers:
docker-compose down
To stop and remove all data:
docker-compose down -vThis project demonstrates:
- Docker containerization and orchestration
- RESTful API design and implementation
- Database design and CRUD operations
- Frontend-backend integration
- Asynchronous JavaScript and fetch API
- Environment configuration and management
- Version control best practices
This is a teaching project. Feel free to:
- Fork the repository
- Create feature branches
- Submit pull requests
- Report issues
This project is created for educational purposes.
For questions or issues:
- Check the troubleshooting section above
- Review the API documentation in
api/product-apis/README.md - Check Docker and Node.js logs for error messages
Happy Coding! 🎉