macOS MontereyにPHP8.0をインストールする

2021年12月24日金曜日

PHP

t f B! P L
macOS Montereyにphpbrewでphp8.0をインストールしようとしたところ、そもそもMontereyにPHPがインストールされていないためインストールできませんでした。このため、brewでPHP8.0をインストールしました。

手順

Homebrewのインストール

次の手順でHomebrewをインストールします。

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Frameworks
==> The Xcode Command Line Tools will be installed.

Press RETURN to continue or any other key to abort:
==> /usr/bin/sudo /bin/mkdir -p /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
==> /usr/bin/sudo /bin/chmod ug=rwx /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
==> /usr/bin/sudo /bin/chmod go-w /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown bach /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Frameworks
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
==> /usr/bin/sudo /usr/sbin/chown -R bach:admin /usr/local/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Users/bach/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/bach/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown -R bach /Users/bach/Library/Caches/Homebrew
==> Searching online for the Command Line Tools
==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing Command Line Tools for Xcode-13.2
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-13.2
Software Update Tool

Finding available software

Downloading Command Line Tools for Xcode
Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode
Done with Command Line Tools for Xcode
Done.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
Password:
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
==> Downloading and installing Homebrew...
remote: Enumerating objects: 198835, done.
remote: Counting objects: 100% (844/844), done.
remote: Compressing objects: 100% (398/398), done.
remote: Total 198835 (delta 455), reused 775 (delta 412), pack-reused 197991
Receiving objects: 100% (198835/198835), 54.51 MiB | 1.54 MiB/s, done.
Resolving deltas: 100% (146769/146769), done.
From https://github.com/Homebrew/brew
 * [new branch]          dependabot/bundler/Library/Homebrew/rubocop-ast-1.15.0 -> origin/dependabot/bundler/Library/Homebrew/rubocop-ast-1.15.0
 * [new branch]          dependabot/bundler/Library/Homebrew/sorbet-0.5.9449 -> origin/dependabot/bundler/Library/Homebrew/sorbet-0.5.9449
 * [new branch]          master     -> origin/master
 * [new tag]             0.1        -> 0.1
 * [new tag]             0.2        -> 0.2
:(中略)
 * [new tag]             3.3.7      -> 3.3.7
 * [new tag]             3.3.8      -> 3.3.8
Updating files: 100% (2720/2720), done.
HEAD is now at 29426f0db Merge pull request #12559 from Bo98/audit-no-tap
==> Tapping homebrew/core
remote: Enumerating objects: 1110320, done.
remote: Counting objects: 100% (102/102), done.
remote: Compressing objects: 100% (59/59), done.
remote: Total 1110320 (delta 59), reused 85 (delta 43), pack-reused 1110218
Receiving objects: 100% (1110320/1110320), 428.52 MiB | 1.21 MiB/s, done.
Resolving deltas: 100% (765348/765348), done.

From https://github.com/Homebrew/homebrew-core
 * [new branch]              master     -> origin/master
Updating files: 100% (6207/6207), done.
HEAD is now at 620f3ef17f6 fuseki: update 4.3.1 bottle.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

opensslのインストール

次の手順でopensslをインストールします。

% brew install openssl
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2021-
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:1b
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.0.0_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/blobs/sha256:a5997d60
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Installing dependencies for openssl@3: ca-certificates
==> Installing openssl@3 dependency: ca-certificates
==> Pouring ca-certificates--2021-10-26.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2021-10-26: 3 files, 208.5KB
==> Installing openssl@3
==> Pouring openssl@3--3.0.0_1.monterey.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@3/certs

and run
  /usr/local/opt/openssl@3/bin/c_rehash

openssl@3 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@3 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@3 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@3/include"

==> Summary
🍺  /usr/local/Cellar/openssl@3/3.0.0_1: 6,415 files, 28MB
==> Running `brew cleanup openssl@3`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> openssl@3
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@3/certs

and run
  /usr/local/opt/openssl@3/bin/c_rehash

openssl@3 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@3 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@3 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@3/include"

phpbrewのインストール(失敗)

次の手順でphpbrewをインストールしようとすると、失敗します。

% curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar
% chmod +x phpbrew.phar
% sudo mv phpbrew.phar /usr/local/bin/phpbrew
% phpbrew init
env: php: No such file or directory

HomebrewでPHP8.0をインストール

phpbrewではインストールできないので、brewでPHP8.0をインストールします。

%brew search php
==> Formulae
brew-php-switcher   php@7.2             phplint             pcp
php                 php@7.3             phpmd               pup
php-code-sniffer    php@7.4             phpmyadmin
php-cs-fixer        php@8.0             phpstan
php-cs-fixer@2      phpbrew             phpunit
% brew install php@8.0
Running `brew update --preinstall`...
==> Downloading https://ghcr.io/v2/homebrew/core/apr/manifests/1.7.0_2
#####################################==> Downloading https://ghcr.io/v2/homebrew/core/apr/blobs/sha256:706df15280f05b
:(中略)
==> /usr/local/Cellar/php@8.0/8.0.13/bin/pear config-set php_bin /usr/local/opt/
==> /usr/local/Cellar/php@8.0/8.0.13/bin/pear update-channels
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

    
        SetHandler application/x-httpd-php
    

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/8.0/

php@8.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@8.0 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/php@8.0/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/php@8.0/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@8.0 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@8.0/lib"
  export CPPFLAGS="-I/usr/local/opt/php@8.0/include"


To restart php@8.0 after an upgrade:
  brew services restart php@8.0
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/php@8.0/sbin/php-fpm --nodaemonize
==> Summary
🍺  /usr/local/Cellar/php@8.0/8.0.13: 500 files, 77.9MB
==> Running `brew cleanup php@8.0`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> php@8.0
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

    
        SetHandler application/x-httpd-php
    

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/8.0/

php@8.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@8.0 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/php@8.0/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/php@8.0/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@8.0 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@8.0/lib"
  export CPPFLAGS="-I/usr/local/opt/php@8.0/include"


To restart php@8.0 after an upgrade:
  brew services restart php@8.0
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/php@8.0/sbin/php-fpm --nodaemonize
%echo 'export PATH="/usr/local/opt/php@8.0/bin:$PATH"' >> ~/.zshrc
%source ~/.zshrc 
%php -v
PHP 8.0.13 (cli) (built: Nov 28 2021 13:28:09) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies

このブログを検索

QooQ