Debug Magento Cloud project with Xdebug

Debug Magento Cloud project with Xdebug

Debug Magento Cloud project with Xdebug

It’s the same as remote debugging on a webserver. Just some differences are listed below
– Magento Cloud has 3 nodes for the staging environment.
– You have to create a ticket on Magento support for enabling Xdebug and get the Xdebug key.

Requirements

To run and use Xdebug, you need the SSH URL for the environment. You can locate the information through the Project Web Interface or your Cloud Onboarding UI.

Configure Xdebug

To configure Xdebug, you need to do the following:

For configuring on Pro plan Staging and Production, you need to enter a ticket for Staging and Production.

Work in a branch

  • Clone your repository to Local Environment
  • Simple
    git clone [repository URL] [folder name]
  • Advance
    git clone [repository URL] –signle-branch –branch [Staging/Production] [folder name]

Enable Xdebug for environments

Xdebug Magento Cloud hosting

To enable Xdebug for your project, add xdebug to the runtime:extensions section of the .magento.app.yaml file.

You can enable Xdebug directly to all Starter environments and Pro Integration environments. For Pro Staging and Production, you need to update this file and enter a Support ticket to have it enabled. We enable Xdebug on those environments for you.

#1. In your local terminal, open the .magento.app.yaml file in a text editor.

#2. In the runtime section, under extensions, add xdebug. For example:

runtime:
    extensions:
        - redis
        - xsl
        - json
        - newrelic
        - sodium
        - xdebug

#3. Save your changes to the .magento.app.yaml file and exit the text editor.

#4. Add, commit, and push the changes to redeploy the environment.

git add git commit "Add xdebug" git push origin <environment-ID>
Code language: HTML, XML (xml)

#5. Submit a ticket to Magento support for enabling the xdebug on the environment.

  • They will provide you the XDEBUG KEY: 3Fcwa0m1xxxxxxxxxxxxxxxxxxxxxxxFcwa0xxxxxxxx

#6. Goes to the Magento project panel and copy 3 ssh options

#7. Open 3 different terminal tabs and access to the ssh via ssh tunnel

  • First remove old xdebug.sock
    1. ssh [SSH_1_URL] rm /run/platform/[env_folder]/xdebug.sock
    2. ssh [SSH_2_URL] rm /run/platform/[env_folder]/xdebug.sock
    3. ssh [SSH_3_URL] rm /run/platform/[env_folder]/xdebug.sock
  • Reconnect with new xdebug.sock via SSH tunnel
    1. ssh -R /run/platform/[env_folder]/xdebug.sock:localhost:9099 -N [SSH_1_URL]
    2. ssh -R /run/platform/[env_folder]/xdebug.sock:localhost:9099 -N [SSH_2_URL]
    3. ssh -R /run/platform/[env_folder]/xdebug.sock:localhost:9099 -N [SSH_3_URL]

#8. Update xdebug port on PHPStorm

#9. Update server mapping (This step could be skip, you can update once PHPStorm capture the xdebug port)

blank

#10. Test debug by adding a break point on pub/index.php and enable xdebug listen (Turn off and turn on the listen for updating the new configuration/port)


blank

#11. Start debug: go to the website url with param ?

  • XDEBUG_SESSION_START=xdebug_session_key_that_provide_by_magento_support
    • Ex: https://abc.staging.com/?XDEBUG_SESSION_START=3Fcwa0m1xxxxxxxxxxxxxxxxxxxxxxxFcwa0xxxxxxxx

#12. Stop debug: go to the website with param ?

  • XDEBUG_SESSION_STOP=3Fcwa0m1xxxxxxxxxxxxxxxxxxxxxxxFcwa0xxxxxxxx
    • ex: https://abc.staging.com/?XDEBUG_SESSION_STOP=3Fcwa0m1xxxxxxxxxxxxxxxxxxxxxxxFcwa0xxxxxxxx

#13. Result

blank

Debug on Linux server to be continued in my next post. Hang on breathlessly.

Have a nice day.

One thought on “Debug Magento Cloud project with Xdebug

Average
5 Based On 1

Leave a Reply

Your email address will not be published. Required fields are marked *