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

WordPressローカル開発環境をつくろう — WP-CLI + Composer —

WordPressローカル開発環境をつくろう — WP-CLI + Composer —

Takashi Kitajima

March 06, 2017
Tweet

More Decks by Takashi Kitajima

Other Decks in Programming

Transcript

  1. 8PSE1SFTTϩʔΧϧ։ൃ؀ڥΛͭ͘Ζ͏
    Š81$-*$PNQPTFSŠ
    ΃ͪͺͳɻ

    View full-size slide

  2. ΩλδϚλΧγ !JOD

    ϑϦʔϥϯε ʙ

    8FCσβΠφʔϓϩάϥϚʔ
    8PSE1SFTTϓϥάΠϯ

    .881'PSNɺ4NBSU$VTUPN'JFMETʜ
    8PSE1SFTTςʔϚ

    )BCBLJSJɺ.JNJ[VLVʜ
    4BTT4UZMVT$44ϑϨʔϜϫʔΫ

    #BTJT

    View full-size slide

  3. 8PSE1SFTTίϛϡχςΟͱͷؔΘΓ
    8PSE#FODI௕࡚ϞσϨʔλʔ
    8PSE$BNQ5PLZP-5
    8PSE$BNQ,BOTBJ࣮ߦҕһϋϯζΦϯ
    8PSE$BNQ,BOTBJ࣮ߦҕһεϐʔΧʔ
    8PSE$BNQ5PLZPεϐʔΧʔ
    FUD

    View full-size slide

  4. ϩʔΧϧ։ൃ؀ڥ͕ͳ͍ͱʜ
    w ϩʔΧϧ։ൃ؀ڥʜαʔόʔ্Ͱ͸ͳࣗ͘෼ͷϚγϯͷ
    தʹ͋Δ։ൃ༻ͷ؀ڥͷ͜ͱ
    w ຖճຖճ͍͍ͪͪ'51ͰϑΝΠϧΛαʔόʔʹ্͛ͨΓ
    %#ͷΤΫεϙʔτΠϯϙʔτΛͯ֬͠ೝ͢Δͷ͸࣌ؒ
    ͷແବ
    w ௚઀αʔόʔͷϑΝΠϧΛૢ࡞͢Δʹͯ͠΋ෳ਺ਓͰಉ
    ࣌ʹ৮Δͱઌ૆ฦΓͷةݥੑ͕ʜ

    View full-size slide

  5. ͳͥϩʔΧϧ։ൃ؀ڥΛ࢖͏ͷ͔
    w ϩʔΧϧʹ։ൃ؀ڥ͕͋Ε͹͙͢ʹಈ࡞֬ೝͰ͖Δ
    w ݱ୅ʹ͸(JU͕͋ΔͷͰෳ਺ਓͰ࡞ۀͨ͠΋ͷΛϚʔδ
    ͯ͠αʔόʔ্ʹ൓ө͢Δͷ΋؆୯

    View full-size slide

  6. .".19".11
    w 8FC੍࡞ʹ͓͚ΔҰൠతͳϩʔΧϧ։ൃ؀ڥͱ͍͑͹
    .".19".11
    w 8PSE1SFTTΛμ΢ϯϩʔυͯ͠ɺσʔλϕʔε༻ҙͯ͠
    ͱ͔ɺ্ཱͪ͛Δ·Ͱ͕ΊΜͲ͍͘͞
    w 8PSE1SFTTͰͷ։ൃʹಛԽͨ͠ઐ༻ͷϩʔΧϧ։ൃ؀ڥ
    ͕͍Ζ͍Ζ͋Δ

    View full-size slide

  7. 8PSE1SFTTͷϩʔΧϧ։ൃ؀ڥ

    View full-size slide

  8. 7$$8ɹIUUQWDDXDD
    w 7BHSBOUΛ࢖ͬͨ8PSE1SFTTͷϩʔΧϧ؀ڥ
    w ʮ7$$8ͷΰʔϧ͸ɺ୯ʹ։ൃ؀ڥΛखͬऔΓૣ͘༻ҙͰ
    ͖ΔΑ͏ʹ͢Δͱ͍͏͜ͱ͚ͩͰ͸ͳ͘ɺ8PSE1SFTT͕ಈ࡞
    ͢Δ؀ڥͦͷ΋ͷΛɺϫʔΫϑϩʔ΋ؚΊͯڞ༗͢Δ͜ͱʯ
    w ศརͳ։ൃऀ޲͚πʔϧ

    81$-*ɺ.BJM$BUDIFSɺ8PSENPWFʜ

    w ؀ڥ࡞Δͷʹʙ෼͘Β͍͔͔Δ

    View full-size slide

  9. 8PDLFSɹIUUQTXDLSHJUIVCJP
    w %PDLFSΛ࢖ͬͨ8PSE1SFTTͷϩʔΧϧ؀ڥ
    w ʮ*55",&4+6454&$0/%450$3&"5&"/&80/&ʯ
    w ؆୯ͳίϚϯυͰΆΜΆΜ8PSE1SFTT؀ڥΛ࡞ͬͨΓফ͠
    ͨΓͰ͖Δ

    View full-size slide

  10. -PDBMCZ'MZXIFFMɹIUUQTMPDBMHFUqZXIFFMDPN
    w 8PSE1SFTTಛԽܕͷ.".19".11త؀ڥ
    w αΠτ͝ͱʹ1)1ɺ.Z42-ͷόʔδϣϯɺ

    8FCαʔόʔ "QBUDIPS/HJOY
    Λબ୒Մೳ
    w ศརͳ։ൃऀ޲͚πʔϧ 81$-*ɺ.BJM$BUDIFSʜ

    w .BD൛ͱ8JOEPXT൛ʢ#FUBʣ

    View full-size slide

  11. <൪֎ฤ>ϏϧτΠϯαʔόʔ
    w Ϛγϯͷ1)1ͱ.Z42-Λ࢖ͬͯϩʔΧϧ؀ڥΛ্ཱͪ͛Δ
    w ͜Ε͸ผʹ8PSE1SFTTಛԽͰ΋ԿͰ΋ͳ͍Ͱ͕͢๻͸͜Ε
    Λ࢖͍ͬͯ·͢ʜ

    w .BD#PPL"JSͷ༰ྔ͕ݶքʹ͍͖ۙͮͯͨͷͰ୤7$$8Λਐ
    ΊͯϏϧτΠϯαʔόʔͰϩʔΧϧ؀ڥΛ࡞ΔΑ͏ʹͨ͠࿩

    IUUQTJODPSHCMPH
    w Ϛγϯ্ͷ.Z42-Λ֤؀ڥͰڞ༗͢ΔͷͰτϥϒϧͱશαΠ
    τ͕ࢮ͵

    View full-size slide

  12. 8PSE1SFTTΛ(JU؅ཧ

    ͢Δͱ͖ͷ໰୊఺

    View full-size slide

  13. Ͳ͜Λ؅ཧ͢Δͷ໰୊
    w υΩϡϝϯτϧʔτ·Δ͝ͱ

    ˠ8PSE1SFTTίΞɺϓϥάΠϯɺςʔϚશ෦
    w XQDPOUFOU·Δ͝ͱ

    ˠϓϥάΠϯɺςʔϚશ෦
    w ࣗ࡞ςʔϚͷΈ

    View full-size slide

  14. υΩϡϝϯτϧʔτ·Δ͝ͱ
    w ϝϦοτ
    w ಉ͡؀ڥΛ؆୯ʹ࠶ݱͰ͖Δ
    w σϝϦοτ
    w ίΞ΍ϓϥάΠϯͳͲɺࣗ෼ͷॻ͍͍ͯͳ͍ίʔυ΋
    ؅ཧର৅ʹͳͬͯ͠·͏

    ˠ8PSE1SFTT͸ࣗಈΞοϓσʔτ͕͋ΔͷͰόʔδϣϯ؅ཧ͕

    ɹ൥ࡶʹͳΔ

    View full-size slide

  15. XQDPOUFOU·Δ͝ͱ
    w ϝϦοτ
    w 8PSE1SFTTίΞ͸؅ཧର৅֎ʹͳΔ
    w σϝϦοτ
    w ίΞ΍ϓϥάΠϯͳͲɺࣗ෼ͷॻ͍͍ͯͳ͍ίʔυ΋
    ؅ཧର৅ʹͳͬͯ͠·͏

    ˠ8PSE1SFTT͸ࣗಈΞοϓσʔτ͕͋ΔͷͰόʔδϣϯ؅ཧ͕

    ɹ൥ࡶʹͳΔ

    View full-size slide

  16. ࣗ࡞ςʔϚͷΈ
    w ϝϦοτ
    w ࣗ෼ͷॻ͍ͨίʔυ͚ͩΛ؅ཧର৅ʹͰ͖Δ
    w σϝϦοτ
    w ͲͷϓϥάΠϯΛΠϯετʔϧ͢Δ΂͖͔ɺͦΕΒͷ
    όʔδϣϯ͸ͲΕΛ࢖͍ͬͯΔͷ͔Λࣗ෼Ͱ೺Ѳͯ͠
    खಈ؅ཧ͠ͳ͚Ε͹ͳΒͳ͍

    View full-size slide

  17. ͭ·ΓͲΕ΋ΊΜͲ͍͘͞

    View full-size slide

  18. w 8PSE1SFTTαΠτίΞϓϥάΠϯςʔϚ
    w ·Δ͝ͱ(JUϦϙδτϦͰ؅ཧ


    ˠطʹ؅ཧ͞Ε͍ͯΔίΞ΍ϓϥάΠϯͷίʔυ·Ͱ

    ɹೋॏ؅ཧͯ͠͠·͏͜ͱʹͳΔ
    w ຊ౰͸ࣗ෼ͷॻ͍ͨίʔυ͚ͩ؅ཧ͍ͨ͠


    ˠίΞ΍ϓϥάΠϯ΋όʔδϣϯͰಈ࡞͕มΘΔͷͰ

    ɹ؅ཧ͠ͳ͍Θ͚ʹ͸͍͔ͳ͍

    View full-size slide

  19. $PNQPTFS
    ͦ͜Ͱ

    View full-size slide

  20. $PNQPTFSɹIUUQTHFUDPNQPTFSPSH
    w 1)1ͷґଘੑ؅ཧπʔϧ
    w ʮશͯͷϓϩδΣΫτ͸ύοέʔδͰ͋Δʯ
    w DPNQPTFSKTPOʹґଘੑΛهड़

    ˠίϐϖͯ͠ଞͷϢʔβʔ͕Ϗϧυͯ͠΋ಉ͡؀ڥ͕࠶ݱʂ

    ˠͭ·Γ͜ͷઃఆϑΝΠϧʹॻ͔Εͨʮґଘੑ৘ใʯ͑͋͞Ε͹

    ɹͦΕΒͷύοέʔδͷʮίʔυʯ͸؅ཧ͢Δඞཁ͕ͳ͍
    w ֎෦ύοέʔδ͸શͯ$PNQPTFSͰ؅ཧ

    ˠʮࣗ෼ͷॻ͍ͨίʔυʯ͚ͩΛ(JU؅ཧͰ͖Δʂ

    View full-size slide

  21. 1BDLBHJTUɹIUUQTQBDLBHJTUPSH
    w $PNQPTFSͷύοέʔδϦϙδτϦ
    w $PNQPTFSͰύοέʔδΛΠϯετʔϧ͢Δͱ͖͸

    جຊతʹ͸1BDLBHJTU͔ΒΠϯετʔϧ͞ΕΔ
    w ࣗ෼Ͱ࡞ͬͨύοέʔδ΋؆୯ʹެ։Ͱ͖Δʂ

    View full-size slide

  22. جຊతͳDPNQPTFSίϚϯυ
    # ύοέʔδΛΠϯετʔϧ (ྫ: Symfony Yaml Component)
    $ composer require symfony/yaml
    # ։ൃ؀ڥͰ͚ͩ࢖͏ύοέʔδΛΠϯετʔϧ (ྫ: phpunit)
    $ composer require --dev phpunit/phpunit
    # composer.jsonɺcomposer.lock ʹهड़͞ΕͨύοέʔδΛΠϯετʔϧ
    $ composer install
    # ύοέʔδΛશ෦ߋ৽
    $ composer update
    # ಛఆͷύοέʔδ͚ͩΛߋ৽ (ྫ: phpunit)
    $ composer update phpunit/phpunit

    View full-size slide

  23. ࢖͍͍ͨ8PSE1SFTTͷϓϥάΠϯ΍ςʔϚ͕

    1BDLBHJTUͰެ։͞Ε͍ͯͳ͔ͬͨΒͲ͏͢Μͷʜ

    View full-size slide

  24. 8PSE1SFTT1BDLBHJTU

    View full-size slide

  25. 8PSE1SFTT1BDLBHJTUɹIUUQTXQBDLBHJTUPSH
    w XPSEQSFTTPSH ެࣜϦϙδτϦ
    Ͱެ։͞Ε͍ͯΔ

    ϓϥάΠϯ΍ςʔϚ͕$PNQPTFSϦϙδτϦͯ͠

    ެ։͞Ε͍ͯΔϛϥʔαΠτ
    w ͭ·ΓɺXPSEQSFTTPSHʹެ։͞Ε͍ͯΔϓϥάΠϯ΍
    ςʔϚ͸શͯ$PNQPTFSͰ؅ཧͰ͖Δʂ

    View full-size slide

  26. Ͱ΋͜ͷล࢖͏ͨΊʹઃఆ͢Δͷ

    ͦ͘ΊΜͲͦ͘͞͏ʜ

    View full-size slide

  27. $PNQPTFS8PSE1SFTT%FWFMPQNFOU,JU
    ͦ͜Ͱʂ

    View full-size slide

  28. $PNQPTFS8PSE1SFTT%FWFMPQNFOU,JU
    IUUQTHJUIVCDPNUPSPVOJUDPNQPTFSXQEFWLJU
    w $PNQPTFSͰ8PSE1SFTTίΞɺϓϥάΠϯɺςʔϚΛ
    ؅ཧͰ͖Δ8PSE1SFTTͷϩʔΧϧ։ൃ؀ڥ
    w 8PSE1SFTT͸ϏϧτΠϯαʔόʔͱͯ͠ىಈͤ͞Δ͜
    ͱ͕Ͱ͖Δ

    View full-size slide

  29. $PNQPTFS8PSE1SFTT%FWFMPQNFOU,JU
    Ͱ։ൃ؀ڥΛͭ͘Ζ͏

    View full-size slide

  30. w .BDͳΒϚγϯ্Ͱ௚઀ಈ͔͢ͷ͸؆୯ɻ

    Ͱ΋8JOEPXTʜ
    w ͱ͍͏͜ͱͰࠓճ͸໦ݪ͞Μʹ࡞ͬͯ௖͍ͨ%PDLFSΠ
    ϝʔδ্Ͱಈ͔͠·͢

    View full-size slide

  31. ϋϯζΦϯ
    # ϏϧυΠϯαʔόʔΛىಈˍϒϥ΢βͰ֬ೝ
    $ composer server
    # ϏϧυΠϯαʔόʔͷఀࢭ
    control + c
    # ςετσʔλΛΠϯϙʔτ͠Α͏
    $ composer import-theme-unit-test

    View full-size slide

  32. $PNQPTFS8PSE1SFTT%FWFMPQNFOU,JU
    Λ࢖ͬͨςʔϚ΍ϓϥάΠϯͷ௥Ճํ๏

    View full-size slide

  33. ϓϥάΠϯͷ௥Ճ
    $ composer require wpackagist-plugin/<Πϯετʔϧ͢ΔϓϥάΠϯͷεϥοά>

    # MW WP Form ΛΠϯετʔϧ͢Δྫ
    $ composer require wpackagist-plugin/mw-wp-form
    # Smart Custom Fields ΛΠϯετʔϧ͢Δྫ
    $ composer require wpackagist-plugin/smart-custom-fields

    View full-size slide

  34. ςʔϚͷ௥Ճ
    $ composer require wpackagist-theme/<Πϯετʔϧ͢ΔςʔϚͷεϥοά>
    # Lightning ΛΠϯετʔϧ͢Δྫ
    $ composer require wpackagist-theme/lightning
    # Habakiri ΛΠϯετʔϧ͢Δྫ
    $ composer require wpackagist-theme/habakiri

    View full-size slide

  35. $PNQPTFSͰ8PSE1SFTTίΞɾ

    ϓϥάΠϯɾςʔϚΛߋ৽͢Δ

    View full-size slide

  36. ;ͭ͏ʹDPNQPTFSίϚϯυͰ0,
    # શ෦ߋ৽
    $ composer update
    # ಛఆͷϓϥάΠϯ͚ͩߋ৽
    $ composer update wpackagist-plugin/mw-wp-form
    # ಛఆͷςʔϚ͚ͩߋ৽
    $ composer update wpackagist-theme/habakiri

    View full-size slide

  37. ͜͜·Ͱ΍ΔͳΒɺ

    ؅ཧը໘Ͱͷૢ࡞΋ͳΔ΂͘

    ίϚϯυͰ΍Γ͍ͨ

    View full-size slide

  38. 81$-*ɹIUUQXQDMJPSH
    w 8PSE1SFTTΛίϚϯυͰૢ࡞Ͱ͖Δπʔϧ
    w ؅ཧը໘͔ΒͰ͖Δ͜ͱ͸جຊతʹԿͰ΋Ͱ͖Δ
    w Α͘࢖͏ૢ࡞΍ઃఆͳͲΛγΣϧεΫϦϓτͱͯ͠·ͱ
    Ί͓͚ͯ͹ࣗಈԽͰ͖ΔͷͰศར
    w $PNQPTFS8PSE1SFTT%FW,JUΛ࢖͑͹ࣗಈతʹΠϯε
    τʔϧ͞ΕΔ

    View full-size slide

  39. Α͘࢖͏81$-*ίϚϯυ
    # ΠϯετʔϧࡁΈͷςʔϚΛ༗ޮԽ
    $ wp theme activate twentyseventeen
    # σʔλϕʔε಺จࣈྻͷஔ׵ (γϦΞϥΠζରԠ)
    $ wp search-replace http://127.0.0.1:8080 http://example.com
    # σʔλϕʔεͷΠϯϙʔτɾΤΫεϙʔτ
    $ wp db import/export

    View full-size slide

  40. ϋϯζΦϯɹ؆୯ͳϓϥάΠϯΛͭͬͯ͘ΈΑ͏
    # ϓϥάΠϯͷ਽ܗΛੜ੒ɾ༗ޮԽ
    # ϢχοτςετɺίʔσΟϯάن໿४ڌςετɺEditorConfig ΋ੜ੒͞ΕΔ !
    $ wp scaffold plugin sample-plugin —activate
    http://localhost:9000/wp-admin
    # γϣʔτίʔυ [phper] Λ௥Ճ͢ΔϓϥάΠϯΛͭͬͯ͘ΈΑ͏
    https://gist.github.com/inc2734/158b59217bee19a2db9b1ba3692a8a6d

    View full-size slide

  41. ϋϯζΦϯɹ؆୯ͳϓϥάΠϯΛͭͬͯ͘ΈΑ͏
    # ϢχοτςετΛ͔͍ͯΈΑ͏
    https://gist.github.com/inc2734/6c0920516d9fb909e9b8d1e89c8bff77
    # ϢχοτςετΛ࣮ߦͯ͠ΈΑ͏
    # PHPUnit ͷΠϯετʔϧ
    $ composer require --dev phpunit/phpunit
    # PHPUnit Λ૸ΒͤΔҰ࣌ςετ؀ڥͷੜ੒
    $ bash ./bin/install-wp-tests.sh wordpress_test root 'hogehoge'
    localhost latest
    # PHPUnit ࣮ߦ
    $ /path/to/wp-content/mu-plugins/vendor/phpunit/phpunit/phpunit

    View full-size slide

  42. ։ൃ؀ڥ͚ͭͬͨ͘Ͳ
    σϓϩΠͲ͏͢Δͷ໰୊

    View full-size slide

  43. w $PNQPTFS8PSE1SFTT%FW,JUͰ͸σΟϨΫτϦ௚Լʹ
    8PSE1SFTTͷϑΝΠϧ͕ల։͞ΕΔͨΊɺجຊతʹ͸
    ·Δ͝ͱαʔόʔ্ʹΞοϓ͢Ε͹0,

    ͨͩ͠XQDPOpHQIQ͸αʔόʔͱϩʔΧϧͰ಺༰͕ҟͳΔͷͰ஫ҙ

    w Ͱ΋'51Ͱຖճߋ৽ͨ͠ϑΝΠϧநग़ͯ͠Ξοϓϩʔυ
    ͢ΔͷΊΜͲ͍͘͞ʜ
    w σʔλϕʔε͸ʜQIQ.Z"ENJOʜΊΜͲ͍͘͞ʜ

    View full-size slide

  44. 8PSENPWFɹIUUQTHJUIVCDPNXFMBJLBXPSENPWF
    w 8PSE1SFTTͷσϓϩΠπʔϧ
    w ίϚϯυҰൃͰ·ΔͬͱΞοϓϩʔυɺμ΢ϯϩʔυ͕
    Մೳ
    w σʔλϕʔε಺ͷ63-ஔ׵΋ࣗಈ
    w $PNQPTFS8PSE1SFTT%FW,JUͰ͸ɺઃఆϑΝΠϧͷ਽
    ܗΛ༻ҙͯ͘͠ΕΔͷͰͦΕΛ࢖͑͹݁ߏ؆୯
    w ৄ͘͠͸IUUQXXXTMJEFTIBSFOFUJODXQEGFT

    View full-size slide

  45. Ͱ΋ॾʑͷࣄ৘Ͱ݁ߏΑ͘ಈ͔ͳ͘ͳΓ·͢ʜ

    View full-size slide

  46. #BTI81%FQMPZ
    ͦ͜Ͱʂ

    View full-size slide

  47. #BTI81%FQMPZɹIUUQTHJUIVCDPNJODCBTIXQEFQMPZ
    w ͭ͘Γ·ͨ͠
    w γΣϧεΫϦϓτͳͷͰΘΓͱ؆୯ʹಈ͘ ͸ͣ

    ཁ81$-*
    w ৄ͘͠͸

    IUUQTHJUIVCDPNJODCBTIXQEFQMPZ

    View full-size slide