Magento 2 and avoiding the rabbit hole

39
@TONEGOLF71 @SPACE48ERS #MAGETITANSIT MAGENTO 2 AND AVOIDING THE RABBIT HOLE Tony Brown

Transcript of Magento 2 and avoiding the rabbit hole

Page 1: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

MAGENTO 2 AND AVOIDING THE RABBIT HOLE

Tony Brown

Page 2: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Imagine…• You’re on the “learn Magento 2” journey

• You hit a tricky problem which isn’t easy to diagnose

• What do you do?

• How can you avoid losing time when learning / fixing problems?

Page 3: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

• Worked on Magento since 1.2

• Technical Director @ Space 48

• Love learning and collaborating

Page 4: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Overview

• Magento 1 to Magento 2

• A learning / debugging technique

• Magento 2 development environment

• Problem solving example in M2

Page 5: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Magento 1 to Magento 2• Architecture changes

• Makes it easier to write tests

• More isolation of code

• More component friendly

• Mechanisms for more targeted changes

• Test coverage

Page 6: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

What does this mean?

• Your WTF per minute rate is going to increase for a while!

Page 7: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Learning / Debugging Technique

• Debugging and Magento : https://youtu.be/xCjPQfuxxxQ

• Time can run away

• Regularly stepping back

• Pomodoro technique

Page 8: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Dev Environment / Infrastructure

• VM via Vagrant

• Nginx, PHP-PFM (v7) with Xdebug

• Percona MySql

• Varnish

• SSL

Page 9: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Varnish

Nginx

8080

HTTP

80

Varnish

Nginx

8080

HTTPS

80

Nginx

443

Page 10: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Problem Solving Example

Page 11: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 12: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 13: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

The problem

Varnish for Full Page Cache

+

SSL for the front-end

=

No navigation menu in Luma

Page 14: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Research for M2 FPC

• Magento Stackexchange

• Same problem, but no answers! http://goo.gl/xK7VQi

• Alan Kent article

• http://devdocs.magento.com

• Other blog posts inc. Alan Storm: http://goo.gl/o4Z107

Page 15: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 16: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

FPC with Varnish

• Varnish holds content responses for URL requests

• Magento decides if a page should be cached or not

• Ajax is used for private data

• ESI is used for finer control of public cache

Page 17: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps

• Are there any errors in the Magento Logs?

• Are there any console errors?

• Examine the HTML output?

Page 18: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Output over HTTPS

Page 19: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Output over HTTP

Page 20: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps

• Examine Varnish cache headers

Page 21: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 22: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 23: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 24: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps• Find the block definition

/vendor/magento/module-theme/view/frontend/layout/default.xml

Page 25: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps

• Step through the code:

• /vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php

Page 26: Magento 2 and avoiding the rabbit hole
Page 27: Magento 2 and avoiding the rabbit hole
Page 28: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

HTTPS = Not working

HTTP = working

Page 29: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 30: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps

• Visit the ESI Controller directly

Page 31: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

HTTPS HTTP

magento2.local/page_cache/block/esi/blocks/[%22catalog.topnav%22]/handles/…

Page 32: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps

• Verify the ESI Controller is being called by Varnish

Page 33: Magento 2 and avoiding the rabbit hole
Page 34: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps• Looking for Varnish logs?… use varnishlog

Page 35: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps• Search for the error

• An old Varnish ticket was found:

By default ignore an <esi:include> with src=" https://..."

Feature +esi_ignore_https treats it as http://... instead.

Page 36: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Debugging Steps

Page 37: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Page 38: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

Conclusion

• Magento 2 has a tricky learning curve

• Take regular breaks to avoid wasting time

• The Varnish FPC implementation is pretty cool!

Page 39: Magento 2 and avoiding the rabbit hole

@TONEGOLF71 @SPACE48ERS

#MAGETITANSIT

THANKS!!

Any questions?