# WooCommerce Complete E-commerce

> WordPress WooCommerce with payment gateways, caching, and search.

- Category: E-Commerce & Business
- Difficulty: intermediate
- Components: wordpress, mysql, redis, elasticsearch, nginx
- Tags: woocommerce, wordpress, ecommerce, payments, php
- Source: https://docker.recipes/ecommerce/woocommerce-complete

## Overview

WordPress is the world's most popular content management system, powering over 40% of all websites. Originally launched in 2003 as a blogging platform, it has evolved into a comprehensive CMS that supports everything from simple blogs to complex enterprise websites. When combined with WooCommerce, WordPress transforms into a powerful e-commerce platform capable of handling everything from small online stores to large-scale retail operations with millions of products.

This stack combines WordPress and WooCommerce with MySQL for robust data storage, Redis for high-performance caching and session management, Elasticsearch for advanced product search capabilities, and NGINX as a high-performance web server and reverse proxy. MySQL's InnoDB storage engine provides ACID compliance for transactional integrity crucial for e-commerce operations, while Redis delivers sub-millisecond response times for cart data and user sessions. Elasticsearch enables sophisticated product search with relevance scoring and faceted navigation, and NGINX's event-driven architecture handles high-traffic loads efficiently.

This configuration is ideal for businesses launching serious e-commerce operations, developers building custom online stores, and agencies managing multiple client shops. The combination provides enterprise-grade performance and scalability while maintaining WordPress's ease of use. With WooCommerce's extensive payment gateway integrations, Redis caching for improved page load times, and Elasticsearch's advanced search capabilities, this stack can handle everything from boutique stores to high-volume marketplaces with complex product catalogs.

## Features

- WooCommerce integration with 100+ payment gateways including PayPal, Stripe, and Square
- Redis Object Cache for sub-millisecond session storage and database query caching
- Elasticsearch full-text search with relevance scoring and product filtering
- MySQL InnoDB storage engine with ACID compliance for secure transaction processing
- NGINX reverse proxy with HTTP/2 support and SSL/TLS termination
- WordPress plugin ecosystem with 60,000+ plugins for unlimited functionality
- ElasticPress integration for advanced product search and analytics
- Redis-based cart persistence and user session management

## Use cases

- High-traffic online stores requiring fast product search and checkout processes
- Multi-vendor marketplaces with complex product catalogs and search requirements
- B2B e-commerce platforms with custom pricing and bulk ordering capabilities
- Digital product stores selling software, courses, or subscription services
- Fashion or electronics retailers needing advanced filtering and search functionality
- International e-commerce sites requiring multiple payment methods and currencies
- Dropshipping businesses managing large product inventories from multiple suppliers

## Prerequisites

- Docker Engine 20.10+ and Docker Compose 2.0+ installed
- Minimum 4GB RAM (2GB for Elasticsearch, 1GB for WordPress/MySQL, 512MB for Redis)
- At least 10GB available disk space for WordPress files and database storage
- Ports 80, 443, and 8081 available on the host system
- Basic understanding of WordPress administration and WooCommerce configuration
- SSL certificates for production deployment (self-signed acceptable for development)

## docker-compose.yml

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

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

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - es_data:/usr/share/elasticsearch/data
    networks:
      - woo_net

  wordpress:
    image: wordpress:latest
    environment:
      - WORDPRESS_DB_HOST=mysql
      - WORDPRESS_DB_NAME=wordpress
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=${MYSQL_PASSWORD}
      - WORDPRESS_CONFIG_EXTRA=
          define('WP_REDIS_HOST', 'redis');
          define('WP_REDIS_PORT', 6379);
    volumes:
      - wordpress_data:/var/www/html
    depends_on:
      - mysql
      - redis
    networks:
      - woo_net

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - wordpress_data:/var/www/html:ro
      - ./ssl:/etc/nginx/ssl:ro
    depends_on:
      - wordpress
    networks:
      - woo_net

  phpmyadmin:
    image: phpmyadmin:latest
    ports:
      - "8081:80"
    environment:
      - PMA_HOST=mysql
      - PMA_USER=wordpress
      - PMA_PASSWORD=${MYSQL_PASSWORD}
    depends_on:
      - mysql
    networks:
      - woo_net

volumes:
  mysql_data:
  redis_data:
  es_data:
  wordpress_data:

networks:
  woo_net:
```

## .env

```bash
# WooCommerce
MYSQL_PASSWORD=secure_mysql_password
MYSQL_ROOT_PASSWORD=secure_root_password

# WordPress at http://localhost
# phpMyAdmin at http://localhost:8081
```

## Usage notes

- WordPress at http://localhost
- phpMyAdmin at http://localhost:8081
- Install WooCommerce via WordPress admin
- Redis Object Cache plugin recommended
- ElasticPress for Elasticsearch integration

## Troubleshooting

- Elasticsearch container exits with 'max virtual memory areas vm.max_map_count too low': Run 'sudo sysctl -w vm.max_map_count=262144' on the host system
- WordPress shows 'Error establishing a database connection': Verify MYSQL_PASSWORD environment variable matches in both wordpress and mysql services
- Redis Object Cache plugin shows 'Connection refused': Ensure Redis container is running and WordPress container can reach redis:6379
- WooCommerce product search returns no results: Install and configure ElasticPress plugin to connect WordPress to the elasticsearch container
- NGINX returns 502 Bad Gateway: Check that wordpress container is healthy and nginx.conf has correct upstream configuration pointing to wordpress:80
- phpMyAdmin access denied: Verify PMA_PASSWORD matches MYSQL_PASSWORD and mysql container is fully initialized before accessing

