Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Ͱ΋·͋ɺSystem PHP͸͔ͭΘ ͳ͍ΑͶ ☞ mojaveͰ7.1.33

Slide 4

Slide 4 text

ఆ൪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ͱ͔΋͍ΔͷͰʣ

Slide 5

Slide 5 text

͔͠͠php-build͸ͭΒ͍ ☞ ۙ೥ϏϧυΛ௨͢ͷʹ೔ࠒͷ܇࿅͕ඞཁɺਏ͍ ☞ XcodeΞϓσͷͨͼʹ͖͑Δ/usr/include ☞ OpenSSLʢLibre SSLʣɺlibxmlɺlib...lib...devel.... ☞ libΛHomeBrewͰ͍ΕΔʹͯ͠΋ΊΜͲ͏ (libͷΞϓσͰͿͬյΕΔ) ☞ vi definitions/hoge ͩΔ͍…

Slide 6

Slide 6 text

HomeBrewͰ௚઀PHP͍ΕΕ͹͍͍ΑͶ $ brew install php $ brew install [email protected] ☞ YES! no build. no dep hell !!!

Slide 7

Slide 7 text

࣮ମ͸͜͜ʹ͋Δ $ 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 [email protected] drwxr-xr-x 3 uzulla staff 96 10 16 21:43 [email protected]

Slide 8

Slide 8 text

/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 )

Slide 9

Slide 9 text

Ͱ΋όʔδϣϯࢦఆ͍͓ͨ͠… ☞ ຖճ /usr/local/Cellar/php/7.4.3/bin/php ͱ͔ࢦఆͯ͠ΒΕͳ͍Ͱ͠ΐ ☞ phpenv͔͓ͭ͏ʁ ☞ php-build͸ϙΠʂ

Slide 10

Slide 10 text

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 !! ☞ Զ͸ଵଦͳಲͰ͢!!

Slide 11

Slide 11 text

ΓΖΜ ☞ 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ͱ͔΋ʣ

Slide 12

Slide 12 text

ϙΠϯτ ☞ ln -s͸͠͹͠͹΍Γ௚͢ඞཁ͕͋Δ ☞ brew upgrade౳Ͱ͖͑ͨΓ͢ΔͷͰ ☞ ϝϯςόʔδϣϯ্͕͕ͬͨΓ͢Δͱ ☞ brew಺ͷpackage໊͕࠷৽൛͸phpɺલ͸[email protected]Ͱඍົ͍ ☞ ·͋ɺյΕΕ͹ؾͮ͘͠ɺ͖͋ΒΊ·͠ΐ͏ ☞ ຖճϏϧυ͢ΔΑΓϚγʂ

Slide 13

Slide 13 text

☞ ಉ࣌ʹɺCellerͷதͷ php.ini͸ফ͑Δ ☞ ΞϓϦ಺Ͱಈతʹini_set͢Δ ☞ πʔϧͰͻͱखؒݮΒ͢ github/uzulla/setmyphpini.php ʮphp setmyphpini.php Λ࣮ߦ͢Δ͜ͱͰɺ࣮ߦͨ͠PHP ͷPHP_CONFIG_FILE_SCAN_DIRʢconf.dʣͷதʹ my_php.iniϑΝΠϧΛίϐʔ͠·͢ɻʯ

Slide 14

Slide 14 text

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͕ͱ͓͍ͬͯΔ͸ͣͰ͢ɺศརʂ

Slide 15

Slide 15 text

☞ ·ɺ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ͱ͔͸ͳ͍Ͷ…

Slide 16

Slide 16 text

Apache͕͓޷͖ʁ ☞ ApacheΛ͍ΕͯɺCGIͰ͏͔͢͝ͱָͰ͠ΐ͏ ScriptAlias /php-bin/ /home/uzulla/.phpenv/versions/7.4.3/bin/ Options ExecCGI Require all granted Action php-script /php-bin/php-cgi SetHandler php-script

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Το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͔ͭͬͯͳ͍͚ͲͶʂ

Slide 20

Slide 20 text

Brewʹແ͍ɺݹ୅ͷPHPʁ ☞ ͍·͸php(7.4), [email protected], [email protected]͕͋ΔɺͦΕΑΓੲͷ͸ແ͍ ☞ ݹ͍Fomula΋tap͢Ε͹ಈ͘…༁Ͱ͸ͳ͍ɺૉ௚ʹೖΒͳ͍ɻ ☞ ࢒೦Ͱ͕͢Ϗϧυ͠·͠ΐ͏ʢݸਓతײ૝ʣ ☞ phpenv install 5.3.3 ☞ welcome back to dep hell !!

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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