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

レンサバけもの道

uzulla
February 10, 2020

 レンサバけもの道

uzulla
2020-02-10 PHPerKaigi 2020 day 1

uzulla

February 10, 2020
Tweet

More Decks by uzulla

Other Decks in Technology

Transcript

  1. Ϩϯαό͚΋ͷಓ

    View full-size slide

  2. uzulla
    Hachioji.pm
    ʮϝʔϧϑΥʔϜ౳Λॻ͍ͯ฻Β͍ͯͨ͠ʯ

    View full-size slide

  3. Ϩϯαό࢖ͬͯΔਓʁ
    (ڍखئ͍·͢)
    (༐ؾͷࢦඪ)

    View full-size slide

  4. Ϩϯαό࢖ͬͨࣄͳ͍ਓʁ
    (ڍखئ͍·͢)
    (ͲΕ͘Β͍ϚδτʔϯͰ࿩͢΂͖͔ࢦඪ)

    View full-size slide

  5. ʮϨϯαό͚΋ͷಓʯͱ͸ʁ

    !
    "࡞๏"͸ແࢹ͢Δ

    "
    ϞμϯʢϞμϯͱ͸ʁʣΑΓʹ͢Δ

    #
    ۀऀ͕ʮΑ͠ʯͱ͠ͳ͍Մೳੑ͕͋Γ·͢

    View full-size slide

  6. • ϨϯαόͰ΋ґଘͤ͞ͳ͍ʮී௨ʯΛ

    View full-size slide

  7. • "ڐՄΛಘΔͳɺँࡑͤΑ"
    • (அΒͳ͍͕ҟ༷ͳͷͰڐՄͮ͠Β͍)
    • DISCRAIMER

    !
    At your OWN risk.
    !

    View full-size slide

  8. ͝ଘ஌Ϩϯαόͱ͸ʁ
    • (جຊ)ߴू໿LAMPɺrootݖݶͳ͠
    • Pros
    • ʢVHෳ਺࡞ΔͳΒʣ҆ͯ͘؅ཧෆཁ
    ϝʔϧͱDNS͕͍ͭͯ͘Δ
    • Cons
    • ݹͯ͘༥௨͕͖͔ͳ͍ˍṖͷ࡞๏
    DNS͕͍͖ͭͯͪΌ͏

    View full-size slide

  9. ฏ͍ͨ͘͏ͱ
    • PaaSͱ͔͸VHҰݸʹ̍ܖ໿Ͱ͔͍ͨʂ
    • ಛʹɺ༡ͼͷίʔυΛಈ͔͓ͯ͘͠ͱ͔
    • ΋͏OSɾϛυϧ΢ΣΞอक͸໘౗
    • ͍͏΄Ͳrootݖݶ͍ΒΜͳ… ʢ˞ݸਓͷײ૝ʣ
    • ʢC֦ு͔ͭΘͳ͍ͳΒʣ

    View full-size slide

  10. Netlify౳͸…
    • DNSͳͲ͸ผʹඞཁ
    • GitωΠςΟϒɺઃఆ͕(஌ࣝ͋Ε͹)Ұॠ
    • ͔͍͍ͬ͜
    • VHҰͭͰ̍ܖ໿
    • ʮGitHub PagesͰ͍͍ͷͰ͸ʁʯ
    • PHP͏͔͝ͳ͍
    !

    View full-size slide

  11. Heroku౳͸…
    • (ͪΌΜͱॻ͚͹)εέʔϧΞ΢τͰ͖Δ
    • ϛυϧ΢ΣΞ͕๛෋
    • σϕϩούʔϑϨϯυϦʔ
    • ENV͕ݸผʹઃఆ͠΍͍͢౳
    • ͔͍͍ͬ͜
    • VHҰͭͰ̍ܖ໿

    View full-size slide

  12. Ϩϯαό͸…
    • εέʔϧΞ΢τͰ͖ͳ͍
    • ஗͍ʢॾઆ͋Δʣ
    • VHͨ͘͞Μͭͬͯ͘΋ఆֹʂ
    • DBͨ͘͞Μͭͬͯ͘΋ఆֹʂ
    • (ϓϥϯʹΑΓ·͢)
    • ؅ཧը໘ϙνϙνˍ͠͹͠଴ͭ͸ͩΔ͍

    View full-size slide

  13. ۙ೥ͷϨϯαό
    • ࣮࣭WordPressʢ΍CMSʣ༻؀ڥ
    • ʮWPಈ͚͹͑͑΍Ζʯͱ͍͏Կ͔͕ݟ͑Δ
    • WP͕ʮਅ໘໨ʯͰҾ͖ͣΒΕ͍ͯΔ(?)
    • → ݁ՌతʹPHPͷόʔδϣϯ͕Ξοϓ͍ͯ͠Δ
    • → ଎౓ͳͲओு࢝͠Ίͨ

    View full-size slide

  14. ࢲͱϨϯαόͷ෇͖߹͍
    • ࢓ࣄͰWordPress
    • ࢓ࣄͰCMS(OSS/ಠࣗ)
    • ࢓ࣄͰϖϥΠνɾίʔϙϨʔταΠτ
    • ϝʔϧαʔόʔ
    • झຯͰ࣮ݧɾ։ൃɾσϞͳͲ

    View full-size slide

  15. ॴͰϨϯαό͸
    • ࣮͸ʢେ఍ʣsshͰ͖Δ
    • ཧ༝ʢधཁʣ͸ෆ໌ɺҰ෦ͷϨϯαό͕ੲ͔Β
    Ͱ͖ͨͷͰԣฒͼͷͨΊʁ
    • Ͳ͜΋ʮࣗݾ੹೚ʯͱ໌ه

    View full-size slide


  16. • sshͰ͖ͳ͍Ϩϯαό͸ආ͚Δ
    • ແྉϨϯαό
    • ҆Ձϓϥϯ
    • ʮΕ͖͋͠ΔΏ͍͠ΐ͋Δۀऀʯ
    • ͜ΕΒͷ࢖͍Έͪ͸ແ͍ʢภݟʣ

    View full-size slide

  17. Φν
    • SSH࢖͏ɺNO MORE FTP
    • ϞμϯͳσϓϩΠΛ͢Δ
    • ʮ޻෉ʯΛ͢Δ
    • Τϥʔ
    • ϩά
    • ͜ΕͰେ׆༻ʂ

    View full-size slide

  18. ݁࿦ɿ ࢖͓͏ʂʂʂ
    • ࠓ͸Ͳ͜Ͱ΋͋Δ(࠷௿ͷϓϥϯͰͳ͚Ε͹)
    • ͭΒ͞ͷׂ̑͸γΣϧΛఘΊΔ͜ͱʹ͋Δ
    • Τϥʔϩά͕tail -fͰ͖Δ͚ͩͰ΋ҧ͏

    View full-size slide

  19. ٯʹΞϯνύλʔϯʮFTPࣗಈԽʯ
    • ʢ҉߸Խͱ͔Ҏલʹʣ
    • ਗ਼͘ਖ਼͍͕͠ɺແବͰ͢(ݸਓͷओு)
    • ͦͷಓ͸མͱ݀͠ʹ௨͍ͯ͡Δ
    • ଞͷ؀ڥͱͷϫʔΫϑϩʔ͕ͣΕ͗͢Δ

    View full-size slide

  20. Ͳ͏׆༻͢Δ͔ʁ
    • লུ
    • ϩάΠϯͨ͠ΒखݩͷPCͱಉ͡ϊϦͰ͍͜͏ʂ
    • ϩάΠϯͯ͠vi͠·͘Ζ͏ʢʁʁʣ

    View full-size slide

  21. Ͱ΋ίϚϯυ͕ແ͍orݹ͍
    • ͨͱ͑͹git 1.8.3ͱ͔…
    • ݹ͍ͳΒɺϏϧυͪ͠Ό͓͏ϗττΪε
    • ͳΜͱେ఍ϏϧυͰ͖Δ؀ڥ͸͋Δ
    $ wget https://ʙ/git-2.9.5.tar.gz
    $ tar xvzf gitʙ; cd gitʙ
    $ configure --prefix=$HOME/local/bin
    $ make -i install # -i is ignore
    $ echo "PATH=$PATH:~/local/bin/" >> ~/.bashrc

    View full-size slide

  22. root͕ͳͯ͘΋Ͳ͏ʹ͔ͳΔ
    • $HOMEʹ͍ΕͪΌ͑͹͍͍ΜͩΑʂ
    • --prefix෇͚ͯϏϧυ
    • PATH௨ͤ͹͍͍͡ΌΜ͍͍͡ΌΜ
    • ʢͨͱ͑͹ʣaws-cliͱ͔s3cliͱ͔΋͍Εͯ͜
    • tarͱ͔͕GNUͰͳ͍? ͍Ε͍ͯ͜͏ʂ

    View full-size slide

  23. ϥϯλΠϜґଘπʔϧ͸Ͳ͏͢Δʁ
    • Perlͱ͔Pythonͱ͔
    • ʮ(prefix෇͖Ͱ)ϥϯλΠϜΛϏϧυʯ
    • ݹ͍ͷΛແཧͯ͠࢖Θͳ͍΄͏͕͍͍
    • ·͋PHPͰॻ͚͹͍͍Μ͡ΌͶʁ
    • ͋Δ͍͸go langͷπʔϧΛ͑ΒͿ

    View full-size slide

  24. ʮͱ͜ΖͰ Linuxbrew͸ʁʯ
    • ґଘΛ͍Ε͍ͯ͘ͱϦιʔε੍ݶʢʁʣͰࢮ͵
    ʢྫɿConoHa WINGʣ
    • (جຊ)૸Βͳ͍ʢྫɿFreeBSDͷ͘͞Βʣ
    • ੈք͸ͦ͜·Ͱ͸؁͘ͳ͔ͬͨ
    • ಈ͘ॴ΋͋Δ͔΋Ͷʂ
    • ͋Δ͍͸΋ͬͱ޻෉͢Δʢলུʣ
    • ۀऀ͞Μ͕Μ͹ͬͯʂ
    !

    View full-size slide

  25. ϨϯαόCLIͷ஫ҙ
    • ࣗݾ੹೚
    • ṖͷϦιʔε੍ݶʹ஫ҙ
    • ಥ೗ϓϩηε͕ࢮ͵
    • ࢦඪ͕͸͖ͬΓͯ͠ͳ͍
    ࣗݾ੹೚͔ͩΒ͔ͨ͠ͳ͍ʢʁʣ
    • ۀऀ͞Μ͕Μ͹ͬͯʂ

    View full-size slide

  26. ͭΒ͞ͷׂ͕̏͜͜
    • ͓࡞๏ͷʮFTP & Ṗͷchrootʯ
    • FTP͸ݖݶ͕Ψό͍ɺϛεͰଈࢮ
    ʢϓϥϯʹΑΔ͕ɺID͕Ұݸ͔͠ͳ͍ʣ
    • ṖͷσΟϨΫτϦߏ੒
    • ܁Γฦ͠ʹͳΔ͕ɺ͓࡞๏͸ແࢹ͠Α͏

    View full-size slide

  27. • ී௨ʹ
    • ʢsshͯ͠ʣgit pull
    • Shell Script/Makefile
    • ansible(౳ sshࣗಈԽ)
    • Deployer
    • ͔ͭ͑͹͍͍ΜͰ͢Α

    View full-size slide

  28. ॳखɿنఆͷDocRootΛແࢹͤΑ
    • ۀऀͷσϑΥΛແࢹͤΑ
    • public_htmlҎԼʹϑΝΠϧΛஔ͔ͳ͍
    • ద౰͓͍ͯSymlink͠Α͏
    • public΍htdocsΛln -s
    • (FollowSymlinks͕Offʁۀऀม͑Α͏͆)

    View full-size slide

  29. ͨͱ͑͹ྫ
    # Ϩϯαόͷઃఆ͸লུ
    $ mkdir ~/repo; cd ~/repo
    $ git clone [email protected]:uzulla/Mizam.git
    $ cd Mizam
    $ make dev-setup # composer instlal౳
    $ ln -s ~/repo/Mizam/public/ \
    ~/www/pktest.8oji.tokyo/public_html

    View full-size slide

  30. ΫϨσϯγϟϧ
    • Tokenͱ͔ΛͲ͜ʹ࢓ࠐΉ͔ʁ
    • VPSಉ༷ʹ dotenv
    • ʮ্Ґʯͷ.htaccess׆༻
    # (publicͷΈɺwwwҎԼʹln -sͨ͠؀ڥͰʣ
    # ~/www/pktest.8oji.tokyo/.htaccess
    SetEnv TOKEN xxxxxx
    # $_ENVͰͳ͘getenv()Ͱऔಘ͢Δ΄͏͕ແ೉
    # symlinkΛͨͲΒͳ͍ͷͰɺ஫ҙ
    # cli͋ΔͳΒແཧ͔ͳʔw

    View full-size slide

  31. ͭ·Γ
    # Appͷ git cloneઌ
    ~/repo/Mizam/
    # ຊ෺ͷhtdocs
    ~/repo/Mizam/public
    # Ϩϯαόઃఆͷhtdocsʢln -s͢Δʣ
    ~/www/pktest.8oji.tokyo/public_html
    # App dirͷʮ֎ʯʹɺenv༻ͷ.htaccessΛͭ͘ΔʢOPʣ
    ~/www/pktest.8oji.tokyo/.htaccess

    View full-size slide

  32. SymlinkΛ࢖͏ࡍͷ஫ҙ
    • ʮͨͲΓํʯ͸؀ڥͰҟͳΔͷͰ஫ҙɾ׆༻
    • PHPͷ__DIR__͸SymlinkΛḷΔ
    realpath()૬౰ʹͳΔ
    →configϑΝΠϧ͸htdocsҎԼͷඞཁ͸ͳ͍
    ※ ެ։σΟϨΫτϦʹ͢Δ৔߹͸஫ҙ
    • Apache͸Symlink͔ݟͳ͍
    (.htaccessͷPathͳͲ)

    View full-size slide

  33. ϨϯαόͰ΋Deployer
    • ssh͕Ͱ͖ΔͷͰɺී௨ʹಈ͘Αʂ
    • (…ࢲͷͨΊͨ͠ݶΓͰ͸)
    • (͘͞Β͸csh͔ͩΒɺbashʹchshඞཁ)
    • deployer͸ϦϞʔτ͕bashલఏΆ͍
    • DBϚΠάϨʔγϣϯπʔϧ΋ಈ͘
    • ྫɿgithub.com/uzulla/deployer-phinx-test

    View full-size slide

  34. DBૢ࡞
    • phpMyadminͱ͔͔ͭͬͯΒΕͳ͍Ͱ͠ΐ
    • ී௨ʹssh ϙʔτϑΥϫʔυͯͭ͠ͳ͝͏
    • Sequel Proͱ͔DBeaverͱ͔…
    • αʔόʔ্Ͱphinxͱ͔΋ಈ͘Αʢલड़ʣ

    View full-size slide

  35. (CI/)CD
    • ͔͍͍ͭͬͯΜͩΑʂʢ͍ͭ͜͠ʣ
    • ʢSymlinkΛ࢖͏ͳΒʣී௨ͷVPSͱ΄΅ಉ༷
    • CIͰσϓϩΠ
    • GitHub Ac5ons
    • ྫɿNetlify ϨϯαόͰͶͬͱΓͱͨ͠ϓΞϚϯ
    ζܧଓతσϓϩΠ

    View full-size slide

  36. (GHA౳Ͱ)CDʹ͢Δͱ…
    • GitHubίϛοτݖݶͰΞΧ΢ϯτ؅ཧͰ͖ͯศར
    • νʔϜʹFTPΞΧ΢ϯτΛࢃ͔ͳͯ͘ྑ͍
    • ௚઀αʔόʔ಺ϑΝΠϧΛ͍͡Βͳ͍
    • ʢ͍ͬͨ͡
    !
    ͕Ͱ͖ͯͯ΋diff͕ݟΕΔʢʣʣ

    View full-size slide


  37. ંฦ͠஍఺
    ͜͜·Ͱʹ࣭໰͕͋Ε͹ϠδͰ͍ͩ͘͞

    View full-size slide

  38. VHʹ͍ͭͯ
    ʢͱ͍͏͔DNSʹ͍ͭͯʣ

    View full-size slide

  39. ϨϯαόͱDNS͸ີ݁߹
    • ίϯύωͰVHͭ͘Δ→AϨίʔυ͕ੜ͑Δ
    • NameServerΛϨϯαόʹ༬͚Δ͔͠ͳ͍
    • ʮNSΛ༬͚ͨ͘ͳ͍ʯʢҰ෦ͷਓؒஊʣ
    • ϨϯαόͷϨϯλϧDNS͸௿ػೳ
    • ଟ͘ͷϨϯαό͸֎෦NSΛߟྀͯ͠ͳ͍ɺͭΒ͍

    View full-size slide

  40. DNS͕ࣗ෼ͰͲ͏ʹ͔Ͱ͖ͳ͍ͱ…
    • ͢ͳ͓ʹෆศ
    • ৭ʑͳΠϯϑϥʹϨϯαόΛ૊ΈࠐΈͮΒ͍
    • Route53Ͱ"ALIAS"࢖͍͍ͨ౳
    • CloudFlareʢ౳ʣ͕͔ͭ͑ͳ͍
    • ۃكʹɺ༬͚ͳ͍ͱVH͕͖Εͳ͍৔߹΋͋Δ
    • ֤ࣾؤுͬͯ΄͍͠
    !

    View full-size slide

  41. େ఍͸Ͳ͏ʹ͔ಈ͘
    • େ఍CNAME͔A͔NSΛΉ͚Ε͹ಈ͖͸͢Δ
    • ·ΕʹϨϯαόͷϗετมߋͰഁ໓͢Δ͜ͱ΋
    • ఘΊΑ͏ʢʁʁʁʣ
    • Ϩϯαό͕ఏڙ͢ΔແྉSSL(Let's Encrypt౳)
    ͕ಈ͔ͳ͍͜ͱ͕͋Δ
    • ߟྀͯ͠ΔͷͰಈ͘ۀऀ΋ʢ͘͞Β౳ʣ

    View full-size slide

  42. Tips ઃఆͷௐ΂ํ
    • Ϩϯαόͷࢦ͕ࣔ͋Ε͹ͦͷΑ͏ʹ
    • ͳ͚Ε͹͠Β΂ͯCNAMEΛઃఆ͢Δ
    • ApexυϝΠϯͳΒ֮ޛͯ͠AΛઃఆ
    # ௐ΂Δྫ
    $ dig {ίϯύωͰ࡞ͬͨυϝΠϯ} @{ʮϨϯαόͷʯNS}

    View full-size slide

  43. $ dig pktest.8oji.tokyo @ns1.dns.ne.jp
    # ུ
    ;; ANSWER SECTION:
    pktest.8oji.tokyo. 3600 IN A 59.106.19.66
    #
    ;; AUTHORITY SECTION:
    pktest.8oji.tokyo. 3600 IN NS ns1.dns.ne.jp.
    pktest.8oji.tokyo. 3600 IN NS ns2.dns.ne.jp.

    View full-size slide

  44. $ dig www.example.com @ns.example.com
    # ུ
    ;; ANSWER SECTION:
    www.example.com. 3534 IN A XXX.XXX.XXX.XXX
    ʔʔʔ
    www.example.com. 3534 IN CNAME www1234.example.jp

    View full-size slide

  45. ΤϥʔϩάͷͭΒ͞
    • ͭΒ͞ͷׂ͕̏͜͜ɺຊ౰ʹශऑ
    • ίϯύωͰݟΔɺFTPͰDLɺݕࡧͳ͠ɺ஍ࠈ
    • (େ఍)ApacheͷErrorLogʹҰॹʹग़͍ͯΔ
    • ͦ΋ͦ΋Offͷ͜ͱ΋ଟ͍

    View full-size slide

  46. ͳͷͰ
    • ࠷௿ݶ
    • ಠࣗͷPathʹग़ྗ͢Δ
    ʢίʔυ͕յΕ͍ͯΔͱؾ͚ͮͳ͍ͷͰʣ
    ίʔυͷ֎ɺphp.ini౳ʹઃఆ͢Δ΂͖
    ʢphp.ini, .htaccess΍.user.iniʣ
    • E_ALLʹ͠·͠ΐ͏

    View full-size slide

  47. ͰɺͲ͏΍ͬͯݟΔʁ
    • ૉ௚ʹssh Ͱtail -fͨ͠Γgrepͨ͠Γ
    • Ξϯνύλʔϯ:ΤϥʔϩάΛࠩ෼DL
    • REST (Restart)
    • ͳΈ͙ͩ·͍͠
    • ਓʹ͸΍Βͳ͚Ε͹͍͚ͳ͍࣌΋͋Δ…

    View full-size slide

  48. Tips:FTPͷREST
    # REST → RESTART
    # lftp ίϚϯυͷ৔߹
    $lftp [email protected]
    # ॳճDL
    > get large.log
    # ࠩ෼DL
    > reget large.log

    View full-size slide

  49. s"pʹ΋͋ΔΑ
    $ sftp [email protected]
    sftp> get large.log
    Fetching /path/to/large.log to large.log
    sftp> reget large.log
    Resuming /path/to/large.log to large.log

    View full-size slide

  50. ΋ͬͱͪΌΜͱ͍ͨ͠
    • ֎෦ϩάαʔϏεͷ׆༻
    • CloudWatch Logs
    • PaperTrail
    • Rollbar(Τϥʔ͸…?)
    • ౳
    • Fatal͕ͰͨΒSlackʹ௨஌ඈ͹͢ͳͲͰ͖Δ

    View full-size slide

  51. ϩάͷૹΓํ
    • File tail͸࢖͑ͳ͍…
    • ʮಈ͚͘Ͳʢ͈́ʯ
    • େ఍ϓϩηεͳͷͰɺෆࢥٞͳྗͰࢮ͵
    • ͳͷͰ
    • Τϥʔɾྫ֎ॲཧʹॻ͘
    • ࣗྗͰtailͯ͠ૹΔ

    View full-size slide

  52. Τϥʔɾྫ֎ॲཧʹॻ͘
    • ·ͬͱ͏ͳίʔυͳΒ͜ΕͰOKͷ͸ͣ
    • (ޙड़ͷྫࢀরʣ
    • ஫ҙɿૹ৴ෛՙ͸ʮߴ͍ʯ
    • No'ceΈ͍ͨͳͷ͸ૹΒͳ͍ɺຊ౰ʹඞཁͳ΋ͷ
    ͚͓ͩ͘Δ΂͖ɻ

    View full-size slide

  53. ࣗલͰΠϕϯτ࣌ʹૹΔ
    • CloudWatch logྫ
    • github.com/uzulla/send-log-to-cloudwatch-log-
    sample.php
    • maxbanton/cwhͰmonologಉ༷
    • (Մೳ͕ͩࣗલૹ৴͸݁ߏ໘౗
    ɹnextSequenceToken͕ͭΒ͍ʣ

    View full-size slide

  54. FATALΛͲ͏͢Δ͔ʁ
    • FatalͰࢮ͵ͱΞϓϦ͔Βඈ͹ͤͳ͍
    • ΤʔδΣϯτͷৗற͸ʮେ఍ʯͰ͖ͳ͍
    • ۪௚ʹϩά૿෼ΛCronͰૹΓ͚ͭΔ͔͠ͳ͍…
    • (ࡶͳͷͰऔΓ͜΅͠͸ͪΐͬͱఘΊΔ)
    • PHP͕ѼઌࢦఆͰSYSLOGΛͳ͛ΒΕΕ͹φΞ…
    ʢpapertrail͸TLSͰSYSLOGΛड͚ΒΕΔʣ

    View full-size slide

  55. CronͰ૿෼ϩάΛૹΔ
    • ϩά͕૿͑ͨ෼͚۪ͩ௚ʹૹΔ
    • Papertrailྫ
    • github.com/uzulla/send-log-to-papertrail-cron.php
    • cronͷMAILTOΛͪΌΜͱઃఆ͠Α͏
    • log truncate͸ผ్Cron౳Ͱ

    View full-size slide

  56. ϩʔςʔγϣϯʹ͍ͭͯ
    • CronͰεΫϦϓτճ͔͢͠ͳ͍…
    • औΓ͜΅͠΍յΕ͕க໋తͳϩά͸ผͰ
    • ʮக໋తϩά͕େྔʹग़ΔΞϓϦͱ͸…͏͝͝ʯ
    #!bash
    cat error.log | gzip -c \
    > /path/to/error.log.`date +%w`.gz
    :> /path/to/error.log

    View full-size slide

  57. ϩάʹ͍ͭͯ
    • க໋తϩάͱग़͠෼͚͢Δͱָ
    # ҙਤͤͣʮͰͪΌͬͨʯϩά͸શ෦க໋తͰ͠ΐʁ
    ini_set('error_log','/path/to/fatal_error.log');
    # ʮҙࣝతʹʯଞϑΝΠϧ΁ʢmonologͰ͍͍Αʂʣ
    error_log( date("Y/m/d H:i:s")." - ".$message."\n",
    3,
    '/path/to/app_error.log');

    View full-size slide

  58. ϨϯαόͷϩάपΓ͸ࠜຊతͳղܾࡦ͕ͳ͍
    • ͩΕ΋ڵຯ͕ͳ͍Μͩͳʂ
    • WPͱ͔ECCUBEͰΤϥʔϩάͪΌΜͱݟͯΔਓ
    ͸͍Δͷ͔ʁ
    • ʮԶΈ͍ͨͳϨϯαόͰϩάݟ͍ͨ෗Ε໺࿠ɺ
    ଞʹɺ͍·͔͍ͬͯ͢Ͷʔ͔ɺ͸͸ʯ
    • ۀऀ͞Μ͕Μ͹ͬͯʂʂ

    View full-size slide

  59. Ϩϯαόతͳ༨ஊ
    • ϑΝΠϧͷύʔϛογϣϯʹ஫ҙ͢Δ͜ͱ
    • ۀऀʹΑΔ͕ɺΓΖΜ͡ΐ͏ಉډਓʹʮΈ͑ͪΌ
    ͏ʯͷͰ
    • (ಉډͰɺPATH͕Θ͔ΓɺPermissionʹΑΔ͕)
    • ʮແҙຯͳ755͸΍ΊΑ͏Ͷʯ

    View full-size slide

  60. όοΫΞοϓ

    View full-size slide

  61. εΫϦϓτॻ͍ͯࣗ෼Ͱ΍Ζ͏
    • ྺ࢙తʹ͍ͬͯɺۀऀͷόοΫΞοϓΛ໡৴ͯ͠
    ͸͍͚ͳ͍
    • ଟॏͰͱΓ·ͬ͠ΐ͍
    • CronͰݻΊͯS3ʹ͋͛Ε͹͓̺
    • ʮόοΫΞοϓ͠΍͍͢ʯΑ͏ʹ࡞Ζ͏
    • (ϨϯαόʹݶΒͳ͍͕)

    View full-size slide

  62. • ۪௚ʹγΣϧεΫϦϓτ
    • tar.gzͰݻΊΔ
    • Symlinkҡ࣋
    • DB΋
    • mysqldump͕·Εʹͳ͍͜ͱ΋͋Δɺ൵͍͠

    View full-size slide

  63. • ετΞઌ͸֎෦ʹ
    • ී௨ʹs3cliͱ͔͍ΕΑ͏ʢԿ౓໨ͩʁʣ
    • S3ଆ͸ϥΠϑαΠΫϧ͕͋ΔͷͰ࠷ߴʂʂ
    (ੈ୅؅ཧΛؙ౤͛Ͱ͖Δ)
    • Amazon S3ͰΦϒδΣΫτͷ༗ޮظݶΛઃఆ

    View full-size slide

  64. ϛϥʔతʹखݩʹམͱ͍ͨ͠ͱ͖͸
    • FTPͤͣɺrsync͕͍͍ͧ
    • (ssh+rsyncͬͯຊ౰ʹศརͩΑͶ…)
    $ rsync -auz -e "ssh" --progress \
    [email protected]:app app_copy
    # ͓޷ΈͰauvzͰ΋Α͍͔ͱ
    • ໪࿦ٯ΋Ͱ͖·͕͢ɺrsyncʢʹݶΒͣϛϥʔΞο
    ϓϩʔυʣ͸ࣄނΓ΍͍͢ͷͰɺdry-runͯ֬͠ೝ
    ͔ͯ͠Βʹ͠Α͏Ͷɻ

    View full-size slide

  65. ֎ܗ؂ࢹ
    • ಛʹίϝϯτͳ͠ɺී௨ʹͦ͏͍͏αʔϏε͔ͭ
    ͑͹ΑΖ͍͠
    • Up$me Robotͱ͔

    View full-size slide

  66. ϝτϦοΫ
    • ϨϯαόͰϝτϦοΫͱ͸…͏͙͙಄͕…
    • Disk༰ྔ͘Β͍͸CronͰ͕Μ͹Ε͹OK
    • ϩάʹ࣮ߦ࣌ؒΛ࢓ࠐΜͰૹ৴ͱ͔…͏ͬ಄͕
    • …
    • ͤΊͯෛՙ੍ݶ͖ͨͱ͖ʹ஌Γ͍ͨ…
    • APIͰऔΓ͍ͨ…ۀऀ͞Μ͕Μ͹ͬͯʂ

    View full-size slide

  67. ॴḨϨϯαό
    • ෛՙΤϥʔ͸֎ܗ؂ࢹͰؾ͔ͮ͘͠ͳ͍͔΋
    • ॴḨϨϯαόɺఘΊ΋؊৺
    • ۪௚ʹΞϓϦνϡʔχϯά͠·͠ΐ͏
    • CDNΦϓγϣϯ΍֎෇͚CDN΋ݕ౼͠·͠ΐ͏

    View full-size slide

  68. ϨϯαόͰ։ൃͯ͠͸ͳΒͳ͍
    • εςʔδϯάఔ౓ʹͯ͠ɺdev͸΍Ίͱ͜͏
    • LAMPͳΒ؀ڥखݩʹͭ͘ΕΔͰ͠ΐ
    • ϞμϯͰ؀ڥґଘͷͳ͍PHPΛॻ͖·͠ΐ͏
    • Ͱ͖ΔͰ͠ΐ͏ʁʢʣ

    View full-size slide

  69. • ؀ڥΛ࡞ΔͳΒDockerΑΓVMͷ΄͏͕Α͍
    • (େ఍ɺઃఆΛ͜ͶΔ͜ͱʹͳΔͷͰ)
    • ൿ఻ͷVM͕Ͱ͖Δ…
    • ansibleͰఆٛ͢Δͱ͔ͨ͠Β͍͍Α
    • ݹͷDistroͰ࡞ΔͷͩΔ͍ͳʔ͆
    • ಠࣗύον΍Distroෆ໌ͳ͜ͱ΋
    • Linuxྗ͕໰ΘΕΔʢʁʣ

    View full-size slide

  70. • ϙʔτϑΥϫʔυͰຊ൪ͷDBΛखݩ؀ڥʹͭͳ͙
    ͘Β͍͸ී௨ʹͰ͖Δ
    • Phinxͱ͔ϚΠάϨʔγϣϯπʔϧ૸ΒͤΔͷ΋Ͱ
    ͖Δ
    • ϨϯαόΛಛผͩͱࢥΘͳ͍͜ͱ͕؊ཁ

    View full-size slide

  71. མͱ݀͠
    • ϛυϧ΢ΣΞઃఆʹ஫ҙ
    • ಛʹMysqlͷsql modeͳͲ
    • php.ini͸ࠜੑͰἧ͑Δ
    • php.iniͷ࿩ - h2ps:/
    /speakerdeck.com/uzulla/
    php-dot-inifalsehua

    View full-size slide

  72. • ΋͏VPSӡ༻ͨ͘͠ͳ͍Ͱ͠ΐ…
    • ʢ̍υϝͰ̍ܖ໿ͷʣPaaSߴ͗͢ϫϩλ
    • ϨϯαόΛrootͷͳ͍Linuxͱͯ͠ݟΔ
    • ࡞๏͸ແࢹ͠Α͏ʢࣗݾ੹೚ʣ
    • ऑ఺Λਖ਼͘͠ೝࣝ͠Α͏
    • ͏·͘΍Ε͹ɺ͍͏΄ͲෳࡶͰ͸ͳ͍

    View full-size slide

  73. ߋʹৄ͍͠ͱ͜Ζ͸
    • Ұॹʹ͚΋ͷಓΛ੾Γ։͖·͠ΐ͏
    • ͓ؾܰʹձ৔΍SNS౳Ͱ͝૬ஊ͍ͩ͘͞ʂ
    • ͜͏͍ͬͨࣄʹલ޲͖ͳϨϯαόۀऀ༷΋ʂʂ

    View full-size slide

  74. Φν
    • ʮ͜ͷҟৗͳ౒ྗͰ΋ɺΑͯ͘τϯτϯͰ͸ʁʯ
    • ʮͦΕͳʯ
    • ͕ۚ͋Δਓ͸ͤͤ͜·͍͜͠ͱΛ͠ͳͯ͘Α͍

    View full-size slide

  75. ׬
    Ҏ͓߱·͚

    View full-size slide

  76. ConoHa WING
    • ࠷͔ۙͭͬͨ
    • ॳظແྉɺैྔ՝ۚϓϥϯ͕͋Δʂʂ
    • ϨϯαόΛͨΊ͢ͷʹ͸ѱ͘ͳ͍
    • ࠷௿ར༻ظ͕ؒͳ͍ʂʂ2ԁ/࣌ʂ
    • CLIͷ੍ݶ͕ṖʢLinuxbrew͕མͪΔʣ
    • ॳظͳ͠࠷௿ར༻ظؒͳ͠ʂ

    View full-size slide

  77. Tips
    • ʮϨϯαόۀऀ໊ʯͰ΍ΓํΛάάΔͳ
    • 95%͕ݹ͍όουϊ΢ϋ΢
    • ʮී௨ʯͷ΍ΓํΛ࣋ͪࠐΈ·͠ΐ͏
    • ʮ͜ͷτʔΫࣗମ͕όουϊ΢ϋ΢ͳͷͰ͸ʁʯ

    View full-size slide

  78. ϚωʔδυαʔϏε࢖͓͏
    • CDN > ෛՙ੍ݶ
    • ϝʔϧૹड৴ > IPϒϩοΫճආɺSPFɺDKIMର
    ԠɺWebhook
    • ؂ࢹ
    • ϨϯαόΑΓߴͭ͘͘ͷ͸΢έΔ

    View full-size slide

  79. PHP͕͏͚͝͹…
    • JVM͕͏͘͝ʂʢʁʣ
    • ࡢ೔ൃද͞ΕͨΊ΋Γʔ͞Μͷphp-java
    • h+ps:/
    /github.com/php-java/php-java
    • ϨϯαόͰJVMݴޠ͕ಈ͘ʂʂʢʁʁʣ
    • ΍ͬͯΈΑ͏ʂʢࡢ೔໷23࣌͝Ζʣ

    View full-size slide

  80. ࢒೦ʢࡢ೔΍ͬͯବ໨ͩͬͨ͆ʣ
    • kotlin?͸͏͘͝Β͍͠Αʂ
    • (CGIΈ͍ͨͳಈ࡞ʹͳΔ͚Ͳ͆)

    View full-size slide

  81. PHPͷόʔδϣϯΞοϓ
    • ͍͖ͳΓ੾Γସ͑ͳ͍
    • खݩ؀ڥͰςετΛ·Θͯ͠Ҡߦ४උ͢Δ
    • Ϩϯαό಺ͰUnitTestΛ·Θ͢ͷ΋͋Γ
    • େ఍৭ʑೖͬͯΔPHPͷ࣮ߦύεʹ஫ҙ
    ʢޙड़ʣ
    • ໷தʹͬͦ͜Γ੾Γସ͑ͯࢼͯ͠ΈΔʢসʣ

    View full-size slide

  82. PHPόΠφϦͷ৔ॴ
    • whichͰ୳ͤͳ͍ɺ֤ࣾͰόϥόϥͰ͢
    • Un-documentͳ͜ͱ͕ଟ͍ͷͰɺphpinfo()ݟΔ

    ͨͱ͑͹खݩͷ͘͞Βͷ৔߹
    $ /usr/local/php/7.3/bin/php -v
    PHP 7.3.12 (cli) (built: Dec 5 2019 10:06:07) ( NTS )
    $ /usr/local/php/4.4/bin/php -v
    PHP 4.4.9 (cli) (built: Dec 4 2019 14:37:37)
    • UnitTest࣌ʹ͸ඞͣόΠφϦͷύεΛࢦఆ͢Δ͜ͱ

    View full-size slide

  83. νϡʔχϯάʢসʣ
    • େ఍(ڞ༗ͱͳΔ)DB͕ʢ࣌ؒଳͰʣ஗͍
    • MysqlΑΓSqlite͕଎͍͜ͱ΋
    • సૹྔͰౖΒΕΔɺCDN΍Ξηοτ഑৴Λ෼͚Δ
    • େ༰ྔσΟεΫͷ࢖͍Έͪ…͏͝͝
    • ϨϯαόͷϓϥϯΞοϓ͸ޮՌͳ͍ࣄଟ͍…
    • ෛՙ໰୊ͳΒɺૉ௚ʹPaaSͱ͔ʹҾͬӽͦ͏

    View full-size slide

  84. ࢼ༻ظؒ
    • େ͖ͳ੠Ͱ͸͍͑ͳ͍͕…
    • ͪΌΜͱղ໿͢Ε͹ʂԿ౓Ͱ΋ʂࢼ༻Ͱ͖Δʂ͜
    ͱ͕ଟ͍ʂ
    • (ݸਓͷײ૝Ͱ͢)
    • ͱΓ͋͑ͣࢼ༻ͯ͠Έ·͠ΐ͏
    • ʢॳظඅ༻จԽͲ͏ʹ͔ͳΓ·ͤΜ͔Ͷʣ

    View full-size slide

  85. Ϩϯαό֤ࣾ΁ͷࢲ৴
    • WordPressҰຊ଍ʹͳͬͯ·ͤΜ͔ʁ
    • PHPͱ͍͏͢͹Β͍͠ݴޠΛಈ͔͢ʮϞμϯͳʯ
    Πϯϑϥͱͯ͠΋͕Μ͹Γ·ͤΜ͔ʁ
    • ֤ࣾʮதͷਓʯ͸ʮΘ͔ͬͯΔʯਓ͕ଟ͍ͷͰɺ
    Θ͔ͬͯΔͷͩͱ͓΋͍·͕͢
    • ঎ചͱͯ͠೉͍͠ͱ͍͏͓࿩͸·͋͋ΔΜͰ͠ΐ
    ͏͕…

    View full-size slide

  86. ฏͨ͘ݴ͏ͱ
    • DocRootͱϩά͚ͩͲ͏ʹ͔ͳΓ·ͤΜ͔Ͷ
    • LinuxbrewʢHomebrewʣೖΔͱ͘͢͝خ͍͠

    View full-size slide