# Sylius

> Symfony-based e-commerce framework.

- Category: E-Commerce & Business
- Difficulty: advanced
- Components: sylius, mysql, redis
- Tags: sylius, symfony, php, ecommerce
- Source: https://docker.recipes/ecommerce/sylius

## Overview

Sylius is a modern, component-based e-commerce framework built on Symfony, designed for developers who need a flexible alternative to monolithic platforms like Magento or WooCommerce. Created in 2011 by Paweł Jędrzejewski, Sylius follows Symfony's philosophy of reusable components and clean architecture, allowing developers to build custom e-commerce solutions without being locked into rigid structures. Unlike traditional e-commerce platforms, Sylius provides a headless-first approach with API Platform integration, making it ideal for omnichannel retail strategies.

This stack combines Sylius with MySQL 8.0 and Redis to create a production-ready e-commerce environment. MySQL serves as the primary data store for product catalogs, orders, customers, and inventory management, while Redis handles session storage, caching layer for product queries, and real-time features like cart persistence. The combination leverages MySQL's ACID compliance for transactional integrity during checkout processes and Redis's sub-millisecond response times for shopping cart operations and product recommendation caching.

This configuration targets mid-to-large scale e-commerce operations, digital agencies building custom storefronts, and businesses requiring headless commerce capabilities. The Symfony foundation makes it particularly attractive to PHP development teams already familiar with modern PHP practices, while the API-first architecture supports mobile apps, progressive web apps, and third-party integrations that traditional e-commerce platforms struggle to handle efficiently.

## Features

- API Platform powered REST and GraphQL APIs for headless commerce implementations
- Component-based architecture allowing selective feature implementation without bloat
- Advanced promotion engine with rule-based discounts, coupons, and cart promotions
- Multi-channel support for managing different storefronts from single admin panel
- Flexible product variant system supporting configurable products with attributes
- Built-in inventory tracking with stock management and reservation system
- Taxation system with zone-based tax calculations and configurable tax categories
- Payment abstraction layer supporting multiple payment gateways through Payum integration

## Use cases

- Digital agencies building custom e-commerce solutions for clients requiring unique designs
- B2B marketplaces needing complex pricing tiers, customer groups, and bulk ordering features
- Fashion retailers managing product variants with size, color, and seasonal collections
- Multi-brand retailers operating separate storefronts with shared inventory management
- Businesses implementing headless commerce with React, Vue, or mobile app frontends
- Companies requiring extensive API integrations with ERP, CRM, or PIM systems
- Subscription commerce platforms needing custom billing cycles and recurring payment handling

## Prerequisites

- Docker Engine 20.10+ and Docker Compose V2 for container orchestration
- 4GB+ RAM recommended for MySQL InnoDB buffer pool and Redis memory allocation
- PHP 8.1+ knowledge for Sylius customization and Symfony framework concepts
- Port 8080 available for Sylius web interface and port 3306 free for MySQL connections
- Basic understanding of Twig templating engine for storefront customization
- Familiarity with Doctrine ORM for entity management and database operations

## docker-compose.yml

```yaml
services:
  sylius:
    image: sylius/sylius:latest
    container_name: sylius
    restart: unless-stopped
    environment:
      APP_ENV: prod
      DATABASE_URL: mysql://${DB_USER}:${DB_PASSWORD}@mysql:3306/${DB_NAME}
    volumes:
      - sylius_data:/srv/sylius/public
    ports:
      - "8080:80"
    depends_on:
      - mysql
      - redis
    networks:
      - sylius

  mysql:
    image: mysql:8.0
    container_name: sylius-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - sylius

  redis:
    image: redis:alpine
    container_name: sylius-redis
    networks:
      - sylius

volumes:
  sylius_data:
  mysql_data:

networks:
  sylius:
    driver: bridge
```

## .env

```bash
DB_ROOT_PASSWORD=rootpassword
DB_NAME=sylius
DB_USER=sylius
DB_PASSWORD=changeme
```

## Usage notes

- Docs: https://docs.sylius.com/
- Access at http://localhost:8080 - built on Symfony PHP framework
- Admin at /admin, default: sylius@example.com / sylius
- Component-based architecture - use only what you need
- API Platform powered REST API for headless commerce
- Plugins marketplace for payments, shipping, promotions

## Troubleshooting

- Sylius returns 500 error on startup: Check DATABASE_URL environment variable format and ensure MySQL container is fully initialized before Sylius starts
- Admin panel shows 'Access Denied' with correct credentials: Clear Redis cache using 'docker exec sylius-redis redis-cli FLUSHALL' and restart Sylius container
- Product images not displaying: Verify sylius_data volume is properly mounted and web server has write permissions to public/media directory
- MySQL connection refused errors: Wait 30-60 seconds after 'docker-compose up' as MySQL 8.0 initialization takes time, especially on first run
- Cart contents disappearing between sessions: Ensure Redis container is running and Sylius session configuration points to Redis server
- Composer memory exhausted during asset installation: Add COMPOSER_MEMORY_LIMIT=-1 environment variable to Sylius service definition

