$30 off During Our Annual Pro Sale. View Details »

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Š ΃ͪͺͳɻ

  2. ΩλδϚλΧγ !JOD   ϑϦʔϥϯε ʙ 
 8FCσβΠφʔϓϩάϥϚʔ  8PSE1SFTTϓϥάΠϯ


    .881'PSNɺ4NBSU$VTUPN'JFMETʜ  8PSE1SFTTςʔϚ
 )BCBLJSJɺ.JNJ[VLVʜ  4BTT4UZMVT$44ϑϨʔϜϫʔΫ
 #BTJT
  3. 8PSE1SFTTίϛϡχςΟͱͷؔΘΓ  8PSE#FODI௕࡚ϞσϨʔλʔ  8PSE$BNQ5PLZP-5  8PSE$BNQ,BOTBJ࣮ߦҕһϋϯζΦϯ  8PSE$BNQ,BOTBJ࣮ߦҕһεϐʔΧʔ 

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

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

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

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

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

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

  13. None
  14. -PDBMCZ'MZXIFFMɹIUUQTMPDBMHFUqZXIFFMDPN w 8PSE1SFTTಛԽܕͷ.".19".11త؀ڥ w αΠτ͝ͱʹ1)1ɺ.Z42-ͷόʔδϣϯɺ
 8FCαʔόʔ "QBUDIPS/HJOY Λબ୒Մೳ w ศརͳ։ൃऀ޲͚πʔϧ

    81$-*ɺ.BJM$BUDIFSʜ  w .BD൛ͱ8JOEPXT൛ʢ#FUBʣ
  15. <൪֎ฤ>ϏϧτΠϯαʔόʔ w Ϛγϯͷ1)1ͱ.Z42-Λ࢖ͬͯϩʔΧϧ؀ڥΛ্ཱͪ͛Δ w ͜Ε͸ผʹ8PSE1SFTTಛԽͰ΋ԿͰ΋ͳ͍Ͱ͕͢๻͸͜Ε Λ࢖͍ͬͯ·͢ʜ  w .BD#PPL"JSͷ༰ྔ͕ݶքʹ͍͖ۙͮͯͨͷͰ୤7$$8Λਐ ΊͯϏϧτΠϯαʔόʔͰϩʔΧϧ؀ڥΛ࡞ΔΑ͏ʹͨ͠࿩


    IUUQTJODPSHCMPH w Ϛγϯ্ͷ.Z42-Λ֤؀ڥͰڞ༗͢ΔͷͰτϥϒϧͱશαΠ τ͕ࢮ͵
  16. 8PSE1SFTTΛ(JU؅ཧ
 ͢Δͱ͖ͷ໰୊఺

  17. Ͳ͜Λ؅ཧ͢Δͷ໰୊ w υΩϡϝϯτϧʔτ·Δ͝ͱ
 ˠ8PSE1SFTTίΞɺϓϥάΠϯɺςʔϚશ෦ w XQDPOUFOU·Δ͝ͱ
 ˠϓϥάΠϯɺςʔϚશ෦ w ࣗ࡞ςʔϚͷΈ

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


    ˠ8PSE1SFTT͸ࣗಈΞοϓσʔτ͕͋ΔͷͰόʔδϣϯ؅ཧ͕
 ɹ൥ࡶʹͳΔ
  19. XQDPOUFOU·Δ͝ͱ w ϝϦοτ w 8PSE1SFTTίΞ͸؅ཧର৅֎ʹͳΔ w σϝϦοτ w ίΞ΍ϓϥάΠϯͳͲɺࣗ෼ͷॻ͍͍ͯͳ͍ίʔυ΋ ؅ཧର৅ʹͳͬͯ͠·͏


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

    खಈ؅ཧ͠ͳ͚Ε͹ͳΒͳ͍
  21. ͭ·ΓͲΕ΋ΊΜͲ͍͘͞

  22. w 8PSE1SFTTαΠτίΞ ϓϥάΠϯ ςʔϚ w ·Δ͝ͱ(JUϦϙδτϦͰ؅ཧ
 
 ˠطʹ؅ཧ͞Ε͍ͯΔίΞ΍ϓϥάΠϯͷίʔυ·Ͱ
 ɹೋॏ؅ཧͯ͠͠·͏͜ͱʹͳΔ w

    ຊ౰͸ࣗ෼ͷॻ͍ͨίʔυ͚ͩ؅ཧ͍ͨ͠
 
 ˠίΞ΍ϓϥάΠϯ΋όʔδϣϯͰಈ࡞͕มΘΔͷͰ
 ɹ؅ཧ͠ͳ͍Θ͚ʹ͸͍͔ͳ͍
  23. $PNQPTFS ͦ͜Ͱ

  24. None
  25. $PNQPTFSɹIUUQTHFUDPNQPTFSPSH w 1)1ͷґଘੑ؅ཧπʔϧ w ʮશͯͷϓϩδΣΫτ͸ύοέʔδͰ͋Δʯ w DPNQPTFSKTPOʹґଘੑΛهड़
 ˠίϐϖͯ͠ଞͷϢʔβʔ͕Ϗϧυͯ͠΋ಉ͡؀ڥ͕࠶ݱʂ
 ˠͭ·Γ͜ͷઃఆϑΝΠϧʹॻ͔Εͨʮґଘੑ৘ใʯ͑͋͞Ε͹
 ɹͦΕΒͷύοέʔδͷʮίʔυʯ͸؅ཧ͢Δඞཁ͕ͳ͍

    w ֎෦ύοέʔδ͸શͯ$PNQPTFSͰ؅ཧ
 ˠʮࣗ෼ͷॻ͍ͨίʔυʯ͚ͩΛ(JU؅ཧͰ͖Δʂ
  26. None
  27. 1BDLBHJTUɹIUUQTQBDLBHJTUPSH w $PNQPTFSͷύοέʔδϦϙδτϦ w $PNQPTFSͰύοέʔδΛΠϯετʔϧ͢Δͱ͖͸
 جຊతʹ͸1BDLBHJTU͔ΒΠϯετʔϧ͞ΕΔ w ࣗ෼Ͱ࡞ͬͨύοέʔδ΋؆୯ʹެ։Ͱ͖Δʂ

  28. جຊతͳ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
  29. ࢖͍͍ͨ8PSE1SFTTͷϓϥάΠϯ΍ςʔϚ͕
 1BDLBHJTUͰެ։͞Ε͍ͯͳ͔ͬͨΒͲ͏͢Μͷʜ

  30. 8PSE1SFTT1BDLBHJTU

  31. None
  32. 8PSE1SFTT1BDLBHJTUɹIUUQTXQBDLBHJTUPSH w XPSEQSFTTPSH ެࣜϦϙδτϦ Ͱެ։͞Ε͍ͯΔ
 ϓϥάΠϯ΍ςʔϚ͕$PNQPTFSϦϙδτϦͯ͠
 ެ։͞Ε͍ͯΔϛϥʔαΠτ w ͭ·ΓɺXPSEQSFTTPSHʹެ։͞Ε͍ͯΔϓϥάΠϯ΍ ςʔϚ͸શͯ$PNQPTFSͰ؅ཧͰ͖Δʂ

  33. Ͱ΋͜ͷล࢖͏ͨΊʹઃఆ͢Δͷ
 ͦ͘ΊΜͲͦ͘͞͏ʜ

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

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

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

  37. w .BDͳΒϚγϯ্Ͱ௚઀ಈ͔͢ͷ͸؆୯ɻ
 Ͱ΋8JOEPXTʜ w ͱ͍͏͜ͱͰࠓճ͸໦ݪ͞Μʹ࡞ͬͯ௖͍ͨ%PDLFSΠ ϝʔδ্Ͱಈ͔͠·͢

  38. ϋϯζΦϯ # ϏϧυΠϯαʔόʔΛىಈˍϒϥ΢βͰ֬ೝ $ composer server # ϏϧυΠϯαʔόʔͷఀࢭ control +

    c # ςετσʔλΛΠϯϙʔτ͠Α͏ $ composer import-theme-unit-test
  39. $PNQPTFS8PSE1SFTT%FWFMPQNFOU,JU Λ࢖ͬͨςʔϚ΍ϓϥάΠϯͷ௥Ճํ๏

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

    ΛΠϯετʔϧ͢Δྫ $ composer require wpackagist-plugin/mw-wp-form # Smart Custom Fields ΛΠϯετʔϧ͢Δྫ $ composer require wpackagist-plugin/smart-custom-fields
  41. ςʔϚͷ௥Ճ $ composer require wpackagist-theme/<Πϯετʔϧ͢ΔςʔϚͷεϥοά> # Lightning ΛΠϯετʔϧ͢Δྫ $ composer

    require wpackagist-theme/lightning # Habakiri ΛΠϯετʔϧ͢Δྫ $ composer require wpackagist-theme/habakiri
  42. $PNQPTFSͰ8PSE1SFTTίΞɾ
 ϓϥάΠϯɾςʔϚΛߋ৽͢Δ

  43. ;ͭ͏ʹDPNQPTFSίϚϯυͰ0, # શ෦ߋ৽ $ composer update # ಛఆͷϓϥάΠϯ͚ͩߋ৽ $ composer

    update wpackagist-plugin/mw-wp-form # ಛఆͷςʔϚ͚ͩߋ৽ $ composer update wpackagist-theme/habakiri
  44. ͜͜·Ͱ΍ΔͳΒɺ
 ؅ཧը໘Ͱͷૢ࡞΋ͳΔ΂͘
 ίϚϯυͰ΍Γ͍ͨ

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

    τʔϧ͞ΕΔ
  47. Α͘࢖͏81$-*ίϚϯυ # ΠϯετʔϧࡁΈͷςʔϚΛ༗ޮԽ $ wp theme activate twentyseventeen # σʔλϕʔε಺จࣈྻͷஔ׵

    (γϦΞϥΠζରԠ) $ wp search-replace http://127.0.0.1:8080 http://example.com # σʔλϕʔεͷΠϯϙʔτɾΤΫεϙʔτ $ wp db import/export
  48. ϋϯζΦϯɹ؆୯ͳϓϥάΠϯΛͭͬͯ͘ΈΑ͏ # ϓϥάΠϯͷ਽ܗΛੜ੒ɾ༗ޮԽ # ϢχοτςετɺίʔσΟϯάن໿४ڌςετɺEditorConfig ΋ੜ੒͞ΕΔ ! $ wp scaffold

    plugin sample-plugin —activate http://localhost:9000/wp-admin # γϣʔτίʔυ [phper] Λ௥Ճ͢ΔϓϥάΠϯΛͭͬͯ͘ΈΑ͏ https://gist.github.com/inc2734/158b59217bee19a2db9b1ba3692a8a6d
  49. ϋϯζΦϯɹ؆୯ͳϓϥάΠϯΛͭͬͯ͘ΈΑ͏ # ϢχοτςετΛ͔͍ͯΈΑ͏ 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
  50. ։ൃ؀ڥ͚ͭͬͨ͘Ͳ σϓϩΠͲ͏͢Δͷ໰୊

  51. w $PNQPTFS8PSE1SFTT%FW,JUͰ͸σΟϨΫτϦ௚Լʹ 8PSE1SFTTͷϑΝΠϧ͕ల։͞ΕΔͨΊɺجຊతʹ͸ ·Δ͝ͱαʔόʔ্ʹΞοϓ͢Ε͹0,
 ͨͩ͠XQDPOpHQIQ͸αʔόʔͱϩʔΧϧͰ಺༰͕ҟͳΔͷͰ஫ҙ  w Ͱ΋'51Ͱຖճߋ৽ͨ͠ϑΝΠϧநग़ͯ͠Ξοϓϩʔυ ͢ΔͷΊΜͲ͍͘͞ʜ w

    σʔλϕʔε͸ʜQIQ.Z"ENJOʜΊΜͲ͍͘͞ʜ
  52. 8PSENPWFɹIUUQTHJUIVCDPNXFMBJLBXPSENPWF w 8PSE1SFTTͷσϓϩΠπʔϧ w ίϚϯυҰൃͰ·ΔͬͱΞοϓϩʔυɺμ΢ϯϩʔυ͕ Մೳ w σʔλϕʔε಺ͷ63-ஔ׵΋ࣗಈ w $PNQPTFS8PSE1SFTT%FW,JUͰ͸ɺઃఆϑΝΠϧͷ਽

    ܗΛ༻ҙͯ͘͠ΕΔͷͰͦΕΛ࢖͑͹݁ߏ؆୯ w ৄ͘͠͸IUUQXXXTMJEFTIBSFOFUJODXQEGFT
  53. Ͱ΋ॾʑͷࣄ৘Ͱ݁ߏΑ͘ಈ͔ͳ͘ͳΓ·͢ʜ

  54. #BTI81%FQMPZ ͦ͜Ͱʂ

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


    IUUQTHJUIVCDPNJODCBTIXQEFQMPZ