---
title: Debug Your Code Within Shopware | Shopware Community Hub
description: >-
  Learn how to debug your code within Shopware, trace issues effectively, and
  apply best practices for troubleshooting.
canonical_url: 'https://hub.shopware.com/learn/unit/debug-your-code-within-shopware'
---

# Debug Your Code Within Shopware

<LearningObjectives>

- Learn how to use debugging tools in Shopware.
- Understand how to set breakpoints and inspect variables.
- Gain knowledge on how to trace the execution flow of your code.
- Learn how to use logging to identify issues.
- Understand common debugging techniques and best practices.

</LearningObjectives>

# Debug Your Code Within Shopware

Great, we are making progress in this learning course. You have learned how to create a plugin, register a storefront controller, add custom data to a product, and connect templates to the storefront.

But what if some parts in your code don't work as expected? How can you find the root cause of the issue? This is where debugging comes into play.

In this learning unit, we will focus on how to debug your code within Shopware. You will learn how to use debugging tools, set breakpoints, inspect variables, trace the execution flow of your code, and use logging to identify issues. Additionally, we will cover common debugging techniques and best practices.

## Environment Setup

There are two different template sources. One being the [Shopware repository](https://github.com/shopware/shopware) that our community commits to and a production-optimized template that is a symfony flex recipe.

If you are using the Symfony Flex template:

```shell
composer create-project shopware/production <project-name>
```

You will need to add the Symfony Webprofiler Bundle to your dev dependencies.

```shell
composer require --dev symfony/web-profiler-bundle
```

<Callout title="Debugging Environment" type="warning">

Debugging should only be done in a safe environment, never in production.

</Callout>

Let's check our .env file for the `APP_ENV` variable. It should be set to `dev`.

```shell
APP_ENV=dev
```

Now we refresh our homepage and should see a Symfony Profiler toolbar. If not, you might have to clear the cache with the following command:

```bash
bin/console cache:clear
```

![img](assets/images/symfony-webprofiler.jpg)

## Symfony Profiler

The [Symfony Profiler](https://symfony.com/doc/current/profiler.html) provides many helpful features and overviews, including a **performance timeline**, **memory usage** and detailed **request insights**. It can help you uncover critical issues in your codebase – for example, when **rules are not active**, or when there are **too many cache tags**.

Some of them are Symfony standard, like:

- Logs
- Events
- Request / Response

Others are Shopware specific:

- Scripts
- Cache tags
- Active rules

![img](assets/images/symfony-profiler.jpg)

## Twig Debug

[Twig dump()](https://twig.symfony.com/doc/3.x/functions/dump.html) is a function that can be used to dump variables in your templates.

```twig
{{ dump(variable) }}
```

If you don't pass a variable, it will dump all variables in the current context. This can be very helpful to see what data is available in your template and how it is structured.

## Xdebug

[Xdebug](https://xdebug.org/) is a PHP extension that helps you debug your code. It provides a lot of valuable information such as **stack traces**, **profiling**, and **code coverage**.

Especially when working on complex data structures, **setting breakpoints** and **inspecting variables** can be very helpful.

Depending on your setup, you can install or activate Xdebug as follows:

### With Devenv

If you are using the [Shopware Devenv](https://developer.shopware.com/docs/guides/installation/devenv.html#enable-xdebug), you can simply **enable Xdebug** through the built-in configuration.

### With LAMP / LEMP

First, install the PHP extension with your package manager:

```bash
sudo apt update
sudo apt install php-xdebug
```

Then configure your `php.ini` file:

```bash
sudo nano /etc/php/8.x/fpm/php.ini

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
```

After that, enable the extension:

```shell
sudo phpenmod xdebug
```

Finally, restart your webserver:

```shell
sudo systemctl restart apache2
```

### With Docker

If you are using Docker, follow this [official Shopware guide](https://developer.shopware.com/docs/guides/installation/setups/docker.html#enable-profiler-debugging-for-php) to enable Xdebug.

<Callout title="Tip" type="info">

Docker will be the **recommended standard setup** for Shopware in the future.

</Callout>

### With Dockware

If you are using [Dockware](https://developer.shopware.com/docs/v6.5/guides/installation/community/dockware.html#dockware-versions), it is recommended to use the **`#dev`** image, where you can simply enable it with a flag.

<Callout title="Note" type="info">

Dockware is planned to be **deprecated** in the future. It is recommended to migrate to a **Docker-based setup** for long-term compatibility.

</Callout>

### IDE Settings in PhpStorm

If you are using PhpStorm, you can configure Xdebug in the IDE settings. Make sure to set the correct path mappings (important to set the public folder here), port, and server.

![img](assets/images/phpstorm-xdebug-settings.jpg)

You can find a detailed guide in the [official PhpStorm documentation](https://www.jetbrains.com/help/phpstorm/2024.3/configuring-xdebug.html).

## Observability

### Logging

You will find your logs in the `var/log` directory of your Shopware root directory. There are different log files for different purposes.

If your environment is set to `dev`, you will see a lot of logs in your `dev.log` file.

Shopware uses the [monolog-bundle](https://symfony.com/doc/current/logging.html#monolog) from Symfony, so you can configure your logging in the `config/packages/dev/monolog.yaml` file.

Find out more about [logging in Shopware](https://developer.shopware.com/docs/guides/hosting/configurations/observability/logging.html#configuration).

### Profiling / Tracing

Finding performance bottlenecks can be a challenging task, especially in complex production setups.

Shopware provides a [profiler interface](https://developer.shopware.com/docs/guides/hosting/configurations/observability/profiling.html#enabling-the-profiler-backends) that can help you identify performance issues.

The profilers differ in the way they are typically used.

#### Ready to use Profilers

**Datadog** and **Tideways** are two popular profiler backends that gather traces and performance data and have predefined dashboards.

#### Custom Profilers

**OpenTelemetry** is open-source and provides a lot of flexibility. You can use it to trace your code and send the data to different backends like Jaeger, Zipkin, or Prometheus.

#### Local Profilers

We mentioned the **Symfony Profiler** already. It provides detailed information about the performance of your code but is only used locally in development environments.

## Other Tools

### Frosh Development Helper

The [Frosh Development Helper](https://github.com/FriendsOfShopware/FroshDevelopmentHelper) is a Shopware plugin that provides a lot of useful tools for developers.

**Some features are:**

- Show Twig includes and blocks in the template as HTML comment.
- Disable annoying storefront error handler.
- Disables Twig cache.
- Twig variables in the Twig tab.
- Generate definition from the command line.

### Meteor Shopware 6 Toolkit

The [Meteor Shopware 6 Toolkit](https://chromewebstore.google.com/detail/meteor-shopware-6-toolkit/onmklnedjfgeaigmkjkldlgpeonpjpnc?pli=1) is a Chrome extension that helps you jump to the right place in the Shopware 6 administration when being on a product detail page or category page.

Helpful when debugging or developing new features.

## Summary

In this learning unit, you have learned:

- How to set up a **debug-friendly environment** (APP_ENV=dev, Webprofiler).
- How to use the **Symfony Profiler** to analyze requests, logs, and cache.
- How to debug Twig templates using the **`dump`** function.
- How to configure and use **Xdebug** for step debugging and breakpoints.
- How to use **logging**, **profiling**, and **observability tools**.
- Which additional tools (**Frosh Development Helper**, **Meteor Shopware 6 Toolkit**) support your debugging workflow.

With these tools and best practices, you can confidently trace, analyze, and fix issues within your Shopware plugins.
