Bitnami Magento Docker Image with xDebug Support

In this document I assumed that you already installed Docker in Windows.

Pull Docker Images from Docker repositories

Step 1:  You can use the docker-compose file found in this url and click the raw button then save to your local preferred location. Magento Docker Compose YML

Step 2:  Open the CLI or PowerShell (which I am using) and go to the file (step 1) location then execute the command: docker compose up OR if you saved the file to a different name you can execute with: docker compose -f .\mylocalfile.yml up

Step 3: Wait to complete everything before you proceed.

 

How to install nano

Optional Utilities that I used is nano to edit the php.ini and I intend to include in this document as part of my personal preference:

Step 1:  In your Docker Desktop under Terminal do the following steps.

Step 2:  $apt-get update

Step 3:  $apt-get install nano

 

Update PHP configuration file

In the docker component you must enable and update the php.ini xDebug section in this folder opt/bitnami/php/etc/php.ini

Step 1:  Go In the very last of the file where you can find the [XDebug] configuration settings.

Step 2:  Replace the entries to the following:

;[XDebug]
zend_extension = xdebug
xdebug.mode = debug
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003
xdebug.output_dir = /tmp
xdebug.remote_handler = dbgp
xdebug.idekey = VSCODE
xdebug.start_with_request = yes

Step 3:  Restart the docker component.

 

Make Visual Studio Code to Support PHP Debugging with xDebug

Step 1:  Open your Visual Studio Code and in the bottom left corner click the Open Remote Window and select Attach to Running Container…

Step 2:  Select the Magento container {/mage000-magento243-1 …}

  VS select the right conainer

Step 3:  Install the PHP xDebug Extensions (this will install in the container).

  vs install php debug to the container

Step 4:  Click the Run and Debug then icon then click the link create a launch.json file then select PHP from the option box.

Step 5:  Replace everything with these new settings below:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
       {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "hostname": "127.0.0.1",
            "port": 9003,
            "stopOnEntry": false,
            "log": true,
            "pathMappings": {
                "/bitnami/magento": "${workspaceFolder}/bitnami/magento"
            }
       }
    ]
}

 

Change the sendmail settings in PHP configuration

Step 1:  set the sendmail_path = /usr/local/bin/phpsendmail.php

Step 2:  create a file phpsendmail.php under the folder /usr/local/bin

#!/usr/bin/php
<?php
        $logfile = '/bitnami/magento/var/mail_log/maillog.htm';
        if(file_exists($logfile) && filesize($logfile) >= 512000)
        {  // Delete 5K size
           unlink($logfile);
        }
        // Get the email content
        $log_output = "<br/>[" . date('Y-m-d H:i:s') . "] ";
        $handle = fopen('php://stdin', 'r');
        $count = 0;
        while(!feof($handle))
        {
                $count++;
                $buffer = trim(fgets($handle));
                if ($count <= 12) # Output header information
                        $log_output .= $buffer . ",";
                else # Output body
                        $log_output .= $buffer;
        }
        // Write the log
        file_put_contents($logfile, $log_output, FILE_APPEND);
?>

 

Note:

If you already have a file our local and wants to just copy to the container, just do the following command in the CLI (just change the source path and the {container_id}):

docker cp C:\phpsendmail.php {container_id}:/usr/local/bin

 

Access Container Volume under Windows Explorer

The container volume can be open in your Windows Explorer through WSL like:

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes

 

Common Problem Encountered:

·       Under the container magento folder, sometimes the folder is not accessible due to permission rights issue. I normally resolve the issue with     chmod -R 777 magento_path and you can actually narrow down to a specific folder like magento/var OR magento/pub/.. . I am using 777 because I am only using this in my development environment, but it should not be the case in the production.

Magento 2.4.x