# OpenCart E-commerce Platform

> Lightweight e-commerce platform with OpenCart, MySQL, and extensions.

- Category: E-Commerce & Business
- Difficulty: beginner
- Components: opencart, mysql, redis, nginx
- Tags: opencart, ecommerce, php, lightweight, extensions
- Source: https://docker.recipes/ecommerce/opencart-complete

## Overview

OpenCart is an open-source PHP-based e-commerce platform that has been powering online stores since 2008. Known for its user-friendly interface and extensive marketplace of themes and extensions, OpenCart provides a lightweight alternative to heavyweight e-commerce solutions like Magento. The platform features a clean admin panel, multi-store support, and over 13,000 modules and themes available through its marketplace, making it popular among small to medium-sized businesses looking to establish an online presence quickly.

This stack combines OpenCart with MySQL 8.0 for robust data storage, Redis for high-performance session management and caching, and includes phpMyAdmin for database administration. MySQL's InnoDB storage engine provides ACID compliance for transaction integrity, while Redis delivers sub-millisecond response times for cart sessions and product caching. The Bitnami OpenCart image comes pre-configured with PHP-FPM and Apache, eliminating the complexity of manual PHP environment setup while maintaining the flexibility to customize themes and extensions.

This configuration is ideal for entrepreneurs launching their first online store, web developers building client e-commerce sites, or businesses migrating from hosted solutions like Shopify to self-hosted platforms. The lightweight nature of OpenCart combined with Redis caching makes this stack capable of handling moderate traffic loads while keeping resource requirements minimal, making it cost-effective for smaller businesses or development environments where performance and simplicity are more important than enterprise-scale features.

## Features

- OpenCart's 13,000+ extension marketplace for payment gateways, shipping modules, and marketing tools
- MySQL 8.0 InnoDB storage engine with ACID compliance for order and inventory transaction integrity
- Redis in-memory caching for lightning-fast shopping cart sessions and product catalog performance
- Multi-store capability allowing management of multiple storefronts from single OpenCart installation
- Built-in SEO optimization with URL rewriting and meta tag management for search engine visibility
- phpMyAdmin web interface for direct database management of products, orders, and customer data
- OpenCart's drag-and-drop layout system for customizing storefront appearance without coding
- Comprehensive admin dashboard with real-time sales analytics and inventory tracking

## Use cases

- Small business owners launching their first online store with limited technical expertise
- Web development agencies building custom e-commerce sites for multiple clients
- Existing brick-and-mortar stores adding online sales channels with inventory synchronization
- Digital product sellers needing lightweight platform for downloadable goods and services
- International businesses requiring multi-currency and multi-language e-commerce capabilities
- Dropshipping operations needing automated order processing and supplier integration
- Development teams prototyping e-commerce features before production deployment

## Prerequisites

- Minimum 2GB RAM recommended (MySQL 1GB + Redis 512MB + OpenCart 512MB + system overhead)
- Ports 80, 443, and 8081 available on host system for web access and phpMyAdmin
- Basic understanding of OpenCart admin panel for initial store configuration and product setup
- SSL certificate files if enabling HTTPS for production e-commerce transactions
- SMTP email credentials for order notifications and customer communication features
- Domain name and DNS configuration for production deployment accessibility

## docker-compose.yml

```yaml
services:
  mysql:
    image: mysql:8.0
    environment:
      - MYSQL_DATABASE=opencart
      - MYSQL_USER=opencart
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - opencart_net

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - opencart_net

  opencart:
    image: bitnami/opencart:latest
    ports:
      - "80:8080"
      - "443:8443"
    environment:
      - OPENCART_DATABASE_HOST=mysql
      - OPENCART_DATABASE_NAME=opencart
      - OPENCART_DATABASE_USER=opencart
      - OPENCART_DATABASE_PASSWORD=${MYSQL_PASSWORD}
      - OPENCART_USERNAME=${OPENCART_USER}
      - OPENCART_PASSWORD=${OPENCART_PASSWORD}
      - OPENCART_EMAIL=${OPENCART_EMAIL}
    volumes:
      - opencart_data:/bitnami/opencart
    depends_on:
      - mysql
    networks:
      - opencart_net

  phpmyadmin:
    image: phpmyadmin:latest
    ports:
      - "8081:80"
    environment:
      - PMA_HOST=mysql
    depends_on:
      - mysql
    networks:
      - opencart_net

volumes:
  mysql_data:
  redis_data:
  opencart_data:

networks:
  opencart_net:
```

## .env

```bash
# OpenCart
MYSQL_PASSWORD=secure_mysql_password
MYSQL_ROOT_PASSWORD=secure_root_password
OPENCART_USER=admin
OPENCART_PASSWORD=secure_admin_password
OPENCART_EMAIL=admin@example.com

# Shop at http://localhost
# Admin at http://localhost/admin
```

## Usage notes

- Shop at http://localhost
- Admin at http://localhost/admin
- Lightweight and fast
- Large extension marketplace
- Easy to customize themes

## Troubleshooting

- OpenCart installation wizard loops endlessly: Ensure OPENCART_DATABASE_PASSWORD matches MYSQL_PASSWORD in environment variables
- Shopping cart sessions not persisting: Verify Redis container is running and accessible on opencart_net network
- Database connection failed error: Wait 30-60 seconds after startup for MySQL to fully initialize before OpenCart connects
- phpMyAdmin shows 'Connection refused': Check that MySQL container is healthy and PMA_HOST points to 'mysql' service name
- OpenCart admin panel returns 404 errors: Ensure /bitnami/opencart volume has proper write permissions for web server
- Product images not displaying: Verify opencart_data volume mount and check image directory permissions in container logs

