Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Running Laravel/PHP on AWS (AWS Builders Day Taiwan 2022)

Running Laravel/PHP on AWS (AWS Builders Day Taiwan 2022)

This is a talk presents at AWS Builders Day Taiwan 2022.

## Blog post

- https://www.ernestchiang.com/zh/posts/2022/running-laravel-php-on-aws/

## Outline

- Laravel/PHP
- Virtualization 👉 Containerization 👉 Orchestration
- Amazon ECS
- Laravel on Amazon ECS
- Reference
- Q & A

Ernest Chiang

June 17, 2022
Tweet

More Decks by Ernest Chiang

Other Decks in Programming

Transcript

  1. UPDATE THIS PRESENTATION HEADER IN SLIDE MASTER
    © 2022, Amazon Web Services, Inc. or its affiliates.
    © 2022, Amazon Web Services, Inc. or its affiliates.
    在 AWS 上運⾏ Laravel/PHP 容器應⽤程式
    Ernest Chiang
    Director of Product & Technology Integration at PAFERS Tec
    h

    AWS Community Hero

    View Slide

  2. UPDATE THIS PRESENTATION HEADER IN SLIDE MASTER
    © 2022, Amazon Web Services, Inc. or its affiliates.
    © 2022, Amazon Web Services, Inc. or its affiliates.
    在 AWS 上運⾏ Laravel/PHP 容器應⽤程式
    Ernest Chiang
    Director of Product & Technology Integration at PAFERS Tec
    h

    AWS Community Hero

    View Slide

  3. © 2022, Amazon Web Services, Inc. or its affiliates.
    拆.解.整.合.的.旅.⼈
    • PAFERS

    Product & Technology Integration

    • AWS

    Community Hero

    • ex-TSMC

    Process Integration Engineer
    Ernest Chiang
    3

    View Slide

  4. PAFERS
    We Build Connected Fitness

    View Slide

  5. PAFERS Bluetooth Classic Fitness Consoles


    View Slide

  6. Bluetooth Event Europe

    View Slide

  7. PAFERS Contributes Industry Knowledge to


    Bluetooth Spec
    https://www.bluetooth.com/specifications/gatt/

    View Slide

  8. PAFERS Fitness Services (PFS)


    The integrated products and services for fitness.
    Smart

    Fitness

    Consoles
    Video

    Streaming
    Services
    Gym Management
    Services

    (GMS)
    Training Content

    Services

    (TCS)

    View Slide

  9. Global PAFERS Edges Footprints

    View Slide

  10. © 2022, Amazon Web Services, Inc. or its affiliates.
    Outline
    ⼤綱
    • Laravel/PHP

    • Virtualization 👉 Containerization 👉 Orchestration

    • Amazon ECS

    • Laravel on Amazon ECS

    • Reference

    • Q & A
    10

    View Slide

  11. img src: https://commons.wikimedia.org/wiki/File:Cair_Pavarel.jpg
    Laravel/PHP
    www.ErnestChiang.com
    issues?

    View Slide

  12. © 2022, Amazon Web Services, Inc. or its affiliates. 12
    That is Cair Paravel, the castle of the four thrones.

    View Slide

  13. © 2022, Amazon Web Services, Inc. or its affiliates.
    從 本機 開始
    13

    View Slide

  14. © 2022, Amazon Web Services, Inc. or its affiliates.
    先⼿動,再⾃動。
    14

    View Slide

  15. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 開發 👉 程式源碼
    15

    View Slide

  16. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 安裝 👉 執⾏環境
    16

    View Slide

  17. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 安裝 👉 作業系統
    17

    View Slide

  18. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 安裝 👉 ⼀台電腦
    18

    View Slide

  19. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 安裝 👉 ⼀台電腦
    我 👉 安裝 👉 作業系統
    我 👉 安裝 👉 執⾏環境
    我 👉 開發 👉 程式源碼
    19
    www.ErnestChiang.com

    View Slide

  20. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 安裝 👉 ⼀台電腦 👈 別⼈做的
    我 👉 安裝 👉 作業系統 👈 別⼈做的
    我 👉 安裝 👉 執⾏環境 👈 別⼈做的
    我 👉 開發 👉 程式源碼 👈 ⾃⼰做的
    20
    www.ErnestChiang.com

    View Slide

  21. © 2022, Amazon Web Services, Inc. or its affiliates.
    我 👉 安裝 👉 ⼀台電腦
    我 👉 安裝 👉 作業系統
    我 👉 安裝 👉 執⾏環境
    我 👉 開發 👉 程式源碼
    21
    www.ErnestChiang.com

    View Slide

  22. © 2022, Amazon Web Services, Inc. or its affiliates.
    在我的電腦上,可以正常執⾏
    22
    www.ErnestChiang.com

    View Slide

  23. © 2022, Amazon Web Services, Inc. or its affiliates.
    在同事電腦上,就。很。炸。
    23
    www.ErnestChiang.com

    View Slide

  24. © 2022, Amazon Web Services, Inc. or its affiliates.
    就別提部署到量產主機了?!
    24

    View Slide

  25. © 2022, Amazon Web Services, Inc. or its affiliates. 25
    www.ErnestChiang.com

    View Slide

  26. © 2022, Amazon Web Services, Inc. or its affiliates. 26
    www.ErnestChiang.com

    View Slide

  27. © 2022, Amazon Web Services, Inc. or its affiliates.
    所以?將 PHP Code 打包?
    27

    View Slide

  28. © 2022, Amazon Web Services, Inc. or its affiliates.
    還是 加上 執⾏環境 ⼀起打包?
    28

    View Slide

  29. © 2022, Amazon Web Services, Inc. or its affiliates.
    還是 外加 作業系統 ⼀起打包?
    29

    View Slide

  30. © 2022, Amazon Web Services, Inc. or its affiliates.
    好,⾄少我們知道這台電腦不能打包。
    30

    View Slide

  31. solution?
    Virtualization
    www.ErnestChiang.com

    View Slide

  32. © 2022, Amazon Web Services, Inc. or its affiliates.
    Creating a virtual version of something;
    32

    View Slide

  33. © 2022, Amazon Web Services, Inc. or its affiliates.
    Creating a virtual version of something;
    33

    View Slide

  34. © 2022, Amazon Web Services, Inc. or its affiliates.
    A hypervisor (or virtual machine monitor, VMM,
    virtualizer) is computer software, firmware or
    hardware that creates and runs virtual machines.
    34

    View Slide

  35. © 2022, Amazon Web Services, Inc. or its affiliates. 35
    www.ErnestChiang.com

    View Slide

  36. © 2022, Amazon Web Services, Inc. or its affiliates. 36
    www.ErnestChiang.com

    View Slide

  37. img src: https://unsplash.com/photos/CJdZ800-Fbs
    part of virtualization
    Containerization
    www.ErnestChiang.com

    View Slide

  38. © 2022, Amazon Web Services, Inc. or its affiliates.
    Operating-system-level virtualization, also known
    as containerization, refers to an operating system
    feature in which the kernel allows the existence
    of multiple isolated user-space instances.
    Such instances, called containers, partitions,
    virtual environments (VEs) or jails (FreeBSD jail or
    chroot jail), may look like real computers from the
    point of view of programs running in them.
    38

    View Slide

  39. © 2022, Amazon Web Services, Inc. or its affiliates.
    Operating-system-level virtualization, also known
    as containerization, refers to an operating system
    feature in which the kernel allows the existence
    of multiple isolated user-space instances.
    Such instances, called containers, partitions,
    virtual environments (VEs) or jails (FreeBSD jail or
    chroot jail), may look like real computers from the
    point of view of programs running in them.
    39

    View Slide

  40. © 2022, Amazon Web Services, Inc. or its affiliates.
    Operating-system-level virtualization, also known
    as containerization, refers to an operating system
    feature in which the kernel allows the existence
    of multiple isolated user-space instances.
    Such instances, called containers, partitions,
    virtual environments (VEs) or jails (FreeBSD jail or
    chroot jail), may look like real computers from the
    point of view of programs running in them.
    40

    View Slide

  41. © 2022, Amazon Web Services, Inc. or its affiliates.
    Operating-system-level virtualization, also known
    as containerization, refers to an operating system
    feature in which the kernel allows the existence
    of multiple isolated user-space instances.
    Such instances, called containers, partitions,
    virtual environments (VEs) or jails (FreeBSD jail or
    chroot jail), may look like real computers from the
    point of view of programs running in them.
    41

    View Slide

  42. © 2022, Amazon Web Services, Inc. or its affiliates. 42
    www.ErnestChiang.com

    View Slide

  43. © 2022, Amazon Web Services, Inc. or its affiliates. 43
    www.ErnestChiang.com

    View Slide

  44. © 2022, Amazon Web Services, Inc. or its affiliates. 44
    www.ErnestChiang.com

    View Slide

  45. © 2022, Amazon Web Services, Inc. or its affiliates. 45
    www.ErnestChiang.com

    View Slide

  46. © 2022, Amazon Web Services, Inc. or its affiliates. 46
    www.ErnestChiang.com

    View Slide

  47. © 2022, Amazon Web Services, Inc. or its affiliates. 47
    www.ErnestChiang.com

    View Slide

  48. © 2022, Amazon Web Services, Inc. or its affiliates. 48
    www.ErnestChiang.com

    View Slide

  49. © 2022, Amazon Web Services, Inc. or its affiliates. 49
    www.ErnestChiang.com

    View Slide

  50. © 2022, Amazon Web Services, Inc. or its affiliates. 50
    > php artisan migrate
    www.ErnestChiang.com

    View Slide

  51. © 2022, Amazon Web Services, Inc. or its affiliates. 51
    www.ErnestChiang.com

    View Slide

  52. © 2022, Amazon Web Services, Inc. or its affiliates. 52
    www.ErnestChiang.com

    View Slide

  53. © 2022, Amazon Web Services, Inc. or its affiliates. 53
    www.ErnestChiang.com

    View Slide

  54. © 2022, Amazon Web Services, Inc. or its affiliates. 54
    www.ErnestChiang.com

    View Slide

  55. © 2022, Amazon Web Services, Inc. or its affiliates. 55
    www.ErnestChiang.com

    View Slide

  56. © 2022, Amazon Web Services, Inc. or its affiliates. 56
    www.ErnestChiang.com

    View Slide

  57. © 2022, Amazon Web Services, Inc. or its affiliates. 57
    www.ErnestChiang.com

    View Slide

  58. © 2022, Amazon Web Services, Inc. or its affiliates. 58
    www.ErnestChiang.com

    View Slide

  59. © 2022, Amazon Web Services, Inc. or its affiliates. 59
    www.ErnestChiang.com

    View Slide

  60. © 2022, Amazon Web Services, Inc. or its affiliates. 60
    www.ErnestChiang.com

    View Slide

  61. © 2022, Amazon Web Services, Inc. or its affiliates. 61
    www.ErnestChiang.com

    View Slide

  62. img src: https://unsplash.com/photos/aEnH4hJ_Mrs
    /,ɔrkʌs`treɪʃʌn/ arrangement
    Orchestration
    www.ErnestChiang.com

    View Slide

  63. © 2022, Amazon Web Services, Inc. or its affiliates. 63

    View Slide

  64. © 2022, Amazon Web Services, Inc. or its affiliates. 64
    www.ErnestChiang.com

    View Slide

  65. © 2022, Amazon Web Services, Inc. or its affiliates. 65
    www.ErnestChiang.com

    View Slide

  66. © 2022, Amazon Web Services, Inc. or its affiliates. 66
    2
    1
    1 2

    View Slide

  67. © 2022, Amazon Web Services, Inc. or its affiliates. 67
    www.ErnestChiang.com

    View Slide

  68. © 2022, Amazon Web Services, Inc. or its affiliates. 68
    2
    1
    1 2

    View Slide

  69. © 2022, Amazon Web Services, Inc. or its affiliates. 69

    View Slide

  70. © 2022, Amazon Web Services, Inc. or its affiliates. 70
    1 2
    www.ErnestChiang.com

    View Slide

  71. img src: Photo by sergio souza on Unsplash
    orchestration
    Amazon ECS
    www.ErnestChiang.com

    View Slide

  72. © 2022, Amazon Web Services, Inc. or its affiliates. 72
    www.ErnestChiang.com

    View Slide

  73. © 2022, Amazon Web Services, Inc. or its affiliates. 73
    1 2

    View Slide

  74. © 2022, Amazon Web Services, Inc. or its affiliates. 74
    1 2
    1 2

    View Slide

  75. © 2022, Amazon Web Services, Inc. or its affiliates. 75

    View Slide

  76. © 2022, Amazon Web Services, Inc. or its affiliates. 76
    www.ErnestChiang.com

    View Slide

  77. © 2022, Amazon Web Services, Inc. or its affiliates. 77
    www.ErnestChiang.com

    View Slide

  78. © 2022, Amazon Web Services, Inc. or its affiliates. 78
    www.ErnestChiang.com

    View Slide

  79. © 2022, Amazon Web Services, Inc. or its affiliates. 79
    www.ErnestChiang.com

    View Slide

  80. © 2022, Amazon Web Services, Inc. or its affiliates. 80
    www.ErnestChiang.com

    View Slide

  81. © 2022, Amazon Web Services, Inc. or its affiliates. 81
    www.ErnestChiang.com

    View Slide

  82. © 2022, Amazon Web Services, Inc. or its affiliates. 82

    View Slide

  83. © 2022, Amazon Web Services, Inc. or its affiliates. 83
    www.ErnestChiang.com
    AWS Fargate
    Amazon EC2

    View Slide

  84. © 2022, Amazon Web Services, Inc. or its affiliates. 84
    www.ErnestChiang.com
    AWS Fargate
    Amazon EC2

    View Slide

  85. img src: Photo by sergio souza on Unsplash
    on Amazon ECS
    Running Laravel
    www.ErnestChiang.com

    View Slide

  86. © 2022, Amazon Web Services, Inc. or its affiliates. 86
    www.ErnestChiang.com
    AWS Fargate
    Fargate LT

    View Slide

  87. © 2022, Amazon Web Services, Inc. or its affiliates. 87
    www.ErnestChiang.com
    AWS Fargate
    Fargate LT

    View Slide

  88. © 2022, Amazon Web Services, Inc. or its affiliates. 88
    www.ErnestChiang.com
    AWS Fargate
    Fargate LT

    View Slide

  89. © 2022, Amazon Web Services, Inc. or its affiliates. 89

    View Slide

  90. © 2022, Amazon Web Services, Inc. or its affiliates. 90
    www.ErnestChiang.com
    ECR
    AWS Fargate
    Fargate LT

    View Slide

  91. © 2022, Amazon Web Services, Inc. or its affiliates. 91
    S. (I) V. O. (image)
    ECR
    www.ErnestChiang.com
    AWS Fargate
    Fargate LT

    View Slide

  92. © 2022, Amazon Web Services, Inc. or its affiliates. 92
    S. (ECS)
    V.
    O.
    ECR
    www.ErnestChiang.com
    AWS Fargate
    Fargate LT

    View Slide

  93. © 2022, Amazon Web Services, Inc. or its affiliates. 93
    S. (CI)
    V.
    O.
    CI
    www.ErnestChiang.com
    AWS Fargate
    Fargate LT

    View Slide

  94. © 2022, Amazon Web Services, Inc. or its affiliates. 94
    www.ErnestChiang.com

    View Slide

  95. © 2022, Amazon Web Services, Inc. or its affiliates. 95
    www.ErnestChiang.com Search "ernest laravel ecs workshop" to download.

    View Slide

  96. © 2022, Amazon Web Services, Inc. or its affiliates. 96
    www.ErnestChiang.com Search "ernest laravel ecs workshop" to download.
    Amazon ECR

    View Slide

  97. Demo
    www.ErnestChiang.com
    never live demo!

    View Slide

  98. © 2022, Amazon Web Services, Inc. or its affiliates.
    Laravel 8.49.1


    with


    PHP 7.4.21


    on


    Different Docker Base Images
    98

    View Slide

  99. © 2022, Amazon Web Services, Inc. or its affiliates. 99
    www.ErnestChiang.com

    View Slide

  100. © 2022, Amazon Web Services, Inc. or its affiliates. 100
    www.ErnestChiang.com

    View Slide

  101. © 2022, Amazon Web Services, Inc. or its affiliates. 101
    www.ErnestChiang.com

    View Slide

  102. © 2022, Amazon Web Services, Inc. or its affiliates.
    Laravel 8.19.0


    with


    PHP 8.0/7.4/7.3


    on


    Buster/Alpine 3.12
    102

    View Slide

  103. © 2022, Amazon Web Services, Inc. or its affiliates. 103
    www.ErnestChiang.com

    View Slide

  104. © 2022, Amazon Web Services, Inc. or its affiliates. 104
    www.ErnestChiang.com

    View Slide

  105. © 2022, Amazon Web Services, Inc. or its affiliates. 105
    www.ErnestChiang.com

    View Slide

  106. 參考資料
    www.ErnestChiang.com
    Reference

    View Slide

  107. © 2022, Amazon Web Services, Inc. or its affiliates.
    參考資料
    Virtualization
    • Wikipedia - Virtualization

    • https://en.wikipedia.org/wiki/Virtualization

    • Playing With Firecracker VMM at COSCUP 2020

    • https://www.ernestchiang.com/en/posts/2020/playing-with-
    fi
    recracker/

    • Firecracker

    • https://
    fi
    recracker-microvm.github.io/
    107

    View Slide

  108. © 2022, Amazon Web Services, Inc. or its affiliates.
    參考資料
    Virtualization
    • Linux 核⼼設計_發展動態回顧

    • https://www.youtube.com/watch?v=-2Pn4B8S1EM

    • Embedded Virtualization applied in Mobile Devices

    • https://www.slideshare.net/jserv/mobile-virtualization
    108

    View Slide

  109. © 2022, Amazon Web Services, Inc. or its affiliates.
    參考資料
    Containerization
    • Wikipedia - OS-level virtualization

    • https://en.wikipedia.org/wiki/OS-level_virtualization
    109

    View Slide

  110. © 2022, Amazon Web Services, Inc. or its affiliates.
    參考資料
    Docker / Laravel / PHP
    • Docker image of nginx + php-fpm (amd64/arm64)

    • https://hub.docker.com/r/dwchiang/nginx-php-fpm

    • Open source (Apache-2.0 license)

    • https://github.com/dwchiang/nginx-php-fpm

    • 50 Stars / 17 Forks
    110

    View Slide

  111. © 2022, Amazon Web Services, Inc. or its affiliates.
    參考資料
    Amazon ECS
    • Ernest's Study Notes on ECS

    • https://www.ernestchiang.com/en/notes/aws/ecs/

    • Nathan Peck's Awesome List

    • https://github.com/nathanpeck/awesome-ecs

    • 技術選型: Amazon ECS Launch Types: EC2 vs. Fargate

    • https://www.ernestchiang.com/zh/posts/2020/technology-selection-amazon-ecs-launch-
    type/

    • 5 Steps: Using Amazon ECS Exec to pass through Fargate/ECS into containers

    • https://www.ernestchiang.com/en/posts/2021/using-amazon-ecs-exec/
    111

    View Slide

  112. © 2022, Amazon Web Services, Inc. or its affiliates.
    參考資料
    Running Laravel on Amazon ECS
    • Workshops: Running Laravel on AWS ECS (using CDK)

    • https://github.com/dwchiang/laravel-on-aws-ecs-workshops

    • CDK Construct Hub

    • https://constructs.dev/

    • CDK patterns for modern application with serverless containers on AWS

    • https://github.com/aws-samples/serverless-container-constructs

    • My study notes on CDK

    • https://www.ernestchiang.com/en/notes/aws/cdk/
    112

    View Slide

  113. © 2022, Amazon Web Services, Inc. or its affiliates. 113
    Search "ernest aws ecs" to download.

    View Slide

  114. © 2022, Amazon Web Services, Inc. or its affiliates.
    Ernest's Blog
    • https://www.ernestchiang.com
    拆解整合的旅⼈
    114

    View Slide

  115. 問與答
    www.ErnestChiang.com
    更多對話

    View Slide

  116. UPDATE THIS PRESENTATION HEADER IN SLIDE MASTER
    © 2022, Amazon Web Services, Inc. or its affiliates.
    Thank you!
    © 2022, Amazon Web Services, Inc. or its affiliates.
    Ernest Chiang
    Twitter @dwchiang
    AWSUG TW
    https://www.facebook.com/
    groups/awsugtw

    View Slide