phpのビルドにつかれた ので phpenv+homebrew

271fad8d53cd1f12f2b4b6d38e3d7bd3?s=47 uzulla
March 27, 2020

phpのビルドにつかれた ので phpenv+homebrew

2020/03/27 @ PHPerKaigi Online (仮)#1
uzulla

271fad8d53cd1f12f2b4b6d38e3d7bd3?s=128

uzulla

March 27, 2020
Tweet

Transcript

  1. phpͷϏϧυʹ͔ͭΕͨ phpenv+homebrew ☞ uzulla ☞ ׬શࣗ୐ۀ຿ରԠܕਓࡐ ☞ 2020/03/27 @ PHPerKaigi

    Online ʢԾʣ#1
  2. લఏ ☞ PHP͸ωΠςΟϒ͕࠷ߴͩΑͶʢݸਓతͳײ૝ʣ ☞ ߴ଎ͩ͠ɺ৭ʑखΛೖΕ΍͍͢͠ ☞ Ͱ΋ɺmysql͸docker͕࠷ߴʂ ☞ ੲ͸Mysql΋͕Μ͹͚ͬͯͨͲͶ… ☞

    https://gist.github.com/uzulla/6028743
  3. Ͱ΋·͋ɺSystem PHP͸͔ͭΘ ͳ͍ΑͶ ☞ mojaveͰ7.1.33

  4. ఆ൪phpenv+php-build $ phpenv install 7.0.0 $ cd some/proj/ $ phpenv

    local 7.0.0 $ php -v php 7.0.0 ☞ ωΠςΠϒPHPer ఆ൪ͷπʔϧ ☞ ࣗ෼͸anyenv͔ΒͷphpenvͰ͢ ☞ ʢnodenvͱ͔rbenvͱ͔΋͍ΔͷͰʣ
  5. ͔͠͠php-build͸ͭΒ͍ ☞ ۙ೥ϏϧυΛ௨͢ͷʹ೔ࠒͷ܇࿅͕ඞཁɺਏ͍ ☞ XcodeΞϓσͷͨͼʹ͖͑Δ/usr/include ☞ OpenSSLʢLibre SSLʣɺlibxmlɺlib...lib...devel.... ☞ libΛHomeBrewͰ͍ΕΔʹͯ͠΋ΊΜͲ͏

    (libͷΞϓσͰͿͬյΕΔ) ☞ vi definitions/hoge ͩΔ͍…
  6. HomeBrewͰ௚઀PHP͍ΕΕ͹͍͍ΑͶ $ brew install php $ brew install php@7.3 ☞

    YES! no build. no dep hell !!!
  7. ࣮ମ͸͜͜ʹ͋Δ $ ls -al /usr/local/Cellar/ |grep php drwxr-xr-x 3 uzulla

    staff 96 3 10 13:30 php drwxr-xr-x 3 uzulla staff 96 10 16 21:43 php@7.1 drwxr-xr-x 3 uzulla staff 96 10 16 21:43 php@7.2
  8. /usr/local/Cellar/php/7.4.3$ ls INSTALL_RECEIPT.json LICENSE NEWS README.md bin composer homebrew.mxcl.php.plist include

    lib pecl sbin share /usr/local/Cellar/php/7.4.3$ bin/php -v PHP 7.4.3 (cli) (built: Feb 20 2020 12:23:37) ( NTS )
  9. Ͱ΋όʔδϣϯࢦఆ͍͓ͨ͠… ☞ ຖճ /usr/local/Cellar/php/7.4.3/bin/php ͱ͔ࢦఆͯ͠ΒΕͳ͍Ͱ͠ΐ ☞ phpenv͔͓ͭ͏ʁ ☞ php-build͸ϙΠʂ

  10. phpenv with brew's php $ ln -s /usr/local/Cellar/php/7.4.3 ~/.phpenv/versions/7.4.3 $

    phpenv local 7.4.3 $ php -v PHP 7.4.3 (cli) (built: Feb 20 2020 12:23:37) ( NTS ) ☞ That's all !! ☞ Զ͸ଵଦͳಲͰ͢!!
  11. ΓΖΜ ☞ phpenv/versionsҎԼʹɺ--prefix=hogeͳײ͡ͰϏϧυͨ͠ PHPΛࢦఆͰ͖Δ(SymlinkͰ΋ྑ͠) ☞ ln -s x.x.x ~/.phpenv/versions/brew ͱ͔Ͱ΋ok

    ☞ $ ln -s 7.4.3 ~/.phpenv/versions/7.4 $ phpenv local 7.4 ͷ΄͏͕ʢޙʑͷखؒΛߟ͑Δͱʣྑ͍͔΋ ☞ ʢࢲ͸php-build΋ࠞࡏ͍ͯ͠ΔͷͰɺbrew7.4.3ͱ͔΋ʣ
  12. ϙΠϯτ ☞ ln -s͸͠͹͠͹΍Γ௚͢ඞཁ͕͋Δ ☞ brew upgrade౳Ͱ͖͑ͨΓ͢ΔͷͰ ☞ ϝϯςόʔδϣϯ্͕͕ͬͨΓ͢Δͱ ☞

    brew಺ͷpackage໊͕࠷৽൛͸phpɺલ͸php@7.3Ͱඍົ͍ ☞ ·͋ɺյΕΕ͹ؾͮ͘͠ɺ͖͋ΒΊ·͠ΐ͏ ☞ ຖճϏϧυ͢ΔΑΓϚγʂ
  13. ☞ ಉ࣌ʹɺCellerͷதͷ php.ini͸ফ͑Δ ☞ ΞϓϦ಺Ͱಈతʹini_set͢Δ ☞ πʔϧͰͻͱखؒݮΒ͢ github/uzulla/setmyphpini.php ʮphp setmyphpini.php

    Λ࣮ߦ͢Δ͜ͱͰɺ࣮ߦͨ͠PHP ͷPHP_CONFIG_FILE_SCAN_DIRʢconf.dʣͷதʹ my_php.iniϑΝΠϧΛίϐʔ͠·͢ɻʯ
  14. C֦ு(ext)͸Ͳ͏͢Δͷʁ $ brew install pkg-config imagemagick $ phpenv version 7.4.3

    (set by ... $ pecl imagick ☞ ·͋ɺී௨ʹpeclͰ͍Ε·͢ɻphpenv͕ͪΌΜͱೖΕ͍ͨphp ʹ޲͍ͯΔ͔ݟ͔ͯΒ΍ͬͯͶ ☞ phpenvͷ͓͔͛Ͱpeclͱ͔phpize͸phpenv local/global͠ ͨ΋ͷʹPath͕ͱ͓͍ͬͯΔ͸ͣͰ͢ɺศརʂ
  15. ☞ ·ɺBrewͷPHP͸ʮେମʯೖ͍ͬͯΔ͚ͲͶ pear, bcmath, calendar, dba, dtrace, exif, ftp, fpm,

    intl, mbregex, mbstring, mysqlnd, opcache-file, pcntl, phpdbg, phpdbg-webhelper, shmop, soap, sockets, sysvmsg, sysvsem, sysvshm, wddx, zip, apxs2, bz2, curl, fpm-user, fpm-group, freetype-dir, gd, gettext, gmp, iconv, icu-dir, jpeg-dir, kerberos, layout, ldap, ldap-sasl, libxml-dir, libedit, libzip, mhash, mysql-sock, mysqli, ndbm, openssl, password-argon2, pdo-dblib, pdo-mysql, pdo-odbc, pdo-pgsql, pdo- sqlite, pgsql, pic, png-dir, pspell, sodium, sqlite3, tidy, unixODBC, webp-dir, xmlrpc, xsl, zlib ☞ imagickͱ͔ɺimagickͱ͔͸ͳ͍Ͷ…
  16. Apache͕͓޷͖ʁ ☞ ApacheΛ͍ΕͯɺCGIͰ͏͔͢͝ͱָͰ͠ΐ͏ ScriptAlias /php-bin/ /home/uzulla/.phpenv/versions/7.4.3/bin/ <Directory /home/uzulla/.phpenv/versions/7.4.3/bin/> Options ExecCGI

    Require all granted </Directory> Action php-script /php-bin/php-cgi <FilesMatch \.php$> SetHandler php-script </FilesMatch>
  17. ☞ ͋·Γʹ໘౗ͩͱࢥ͏ͷͰɺ੿࡞ͷ͜Ε͕͋Γ·͢ ☞ github/uzulla/apachehere ☞ ʮ޷͖ͳσΟϨΫτϦͰapachehereͱλΠϓ͢Δͱɺͦ͜ ΛDocumentRootͱͯ͠Apache্ཱ͕͕ͪΓ·͢ʯ ☞ ʮphpenv͕ΠϯετʔϧࡁΈͳΒ͹ɺͦͪΒͷphpΛ͔ͭ ͍·͢ɻphpenvͷlocalࢦఆ΋൓ө͞Ε·͢ʯ

  18. CGI͸͓ݏ͍ʁ ☞ brew͸͜ͷ΁Μʹso͕͋Γ·͢ɺҎԼུɻ Cellar/php/7.4.3/lib/httpd/modules/libphp7.so ☞ apachehereΛ࢖͏৔߹ ~/.phpenv/versions/x.x.x/libexec/libphp7.so ʹϑΝΠϧΛ͓͚͹͓̺ ☞ (php-buildͩͱ͜͜ʹੜ੒͞ΕΔΜΑ)

  19. Τοnginx? $ which php-fpm /Users/uzulla/.anyenv/envs/phpenv/shims/php-fpm /usr/local/Cellar/php/7.4.3/sbin$ ls php-fpm ☞ ΋ͪΖΜphp-fpm΋Brewͷphpʹ͸͋ΔΑʂ

    ☞ ·͋ɺԶ͸(ϩʔΧϧ։ൃ؀ڥͰ)nginx͔ͭͬͯͳ͍͚ͲͶʂ
  20. Brewʹແ͍ɺݹ୅ͷPHPʁ ☞ ͍·͸php(7.4), php@7.3, php@7.2͕͋ΔɺͦΕΑΓੲͷ͸ແ͍ ☞ ݹ͍Fomula΋tap͢Ε͹ಈ͘…༁Ͱ͸ͳ͍ɺૉ௚ʹೖΒͳ͍ɻ ☞ ࢒೦Ͱ͕͢Ϗϧυ͠·͠ΐ͏ʢݸਓతײ૝ʣ ☞

    phpenv install 5.3.3 ☞ welcome back to dep hell !!
  21. ʮLD_LIBͿͬյΕΔͷϚδͿͬࡴ͢Ϛϯʯ΁ͷࢲ৴ ☞ ʢΘ͔Βͳ͍ͻͱ͸͖ʹ͠ͳͯ͘Α͍࿩ʣ ☞ brew͕Ξϓσͬͯ͘͠͞ɺ ਅ৺ࠐΊͯͭͬͨ͘όΠφϦ͕ͿͬյΕΔ→ΩϨͦ͏ ☞ Disk͕෋߽ͳਓ͸HOMEBREW_NO_INSTALL_CLEANUPࢦఆ΋Α͍ ☞ Ϗϧυ࣌ʹɺ͍͍ͪͪࡉ͔͘CellerҎԼ΁ͷPATHࢦఆඞཁ

    ͕ͩ…
  22. ☞ ελςΟοΫϏϧυ͍ͨ͠ͳʙʙɺ Ͱ΋PHPͰελςΟοΫϏϧυ͸ݬͳͷ͸༗໊Ͱ͢Ͷʁ ☞ ldd phpͯ͠ɺͰͯ͘ΔsoΛશ෦͔͖͋ͭΊͯͲ͔ͬʹ์Γࠐ ΜͰɺLD_LIBRARY_PATH௨͢ͱ͍͏ςΫ ☞ ʢͱ͸͍͑ɺϦιʔεϑΝΠϧ͸…ʁʣ

  23. fin ☞ ωΠςΟϒ࠷ߴʂ ☞ ʮ࠷৽൛Ͱ͍͍ͳΒʯBrewΛ׆༻͢Δͱָ͘͢͝Ͱ͢ɻ ☞ ࢲ͸ତམ͠·ͨ͠ɻ ☞ ಉ͡ςΫ͸Linux(Brew)Ͱ΋Ͱ͖·͢ ʢ͕ɺ͋ͬͪ͸ͦΜͳϏϧυͰࢮͳͳ͍ͳʣ

    ☞ ຊ൪؀ڥͰ΋࢖͑ΔςΫͰ͕͢ɺૉ௚ʹaptָ͕Ͱ͢()