気持ちが良いIT技術を学ぶ

HomebrewでPHP8.x設定

2023年07月13日に更新, By 管理者

HomebrewでPHP8.x設定

- PHP8.1設置

$ brew install php@8.1
Running `brew update --auto-update`...
==> Downloading https://formulae.brew.sh/api/formula.json
######################################################################## 100.0%
==> Downloading https://formulae.brew.sh/api/cask.json
######################################################################## 100.0%
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/services).
No changes to formulae.
..
..
Removing: /Users/gisunseo/Library/Logs/Homebrew/protobuf... (64B)
Removing: /Users/gisunseo/Library/Logs/Homebrew/jpeg-turbo... (64B)
Pruned 0 symbolic links and 15 directories from /opt/homebrew
==> Caveats
==> php@8.1
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /opt/homebrew/opt/php@8.1/lib/httpd/modules/libphp.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

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

The php.ini and php-fpm.ini file can be found in:
    /opt/homebrew/etc/php/8.1/

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

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

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


To start php@8.1 now and restart at login:
  brew services start php@8.1
==> httpd
DocumentRoot is /opt/homebrew/var/www.

The default ports have been set in /opt/homebrew/etc/httpd/httpd.conf to 8080 and in
/opt/homebrew/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

- PHPパス設定

% vi ~/.zshrc
export PATH="/opt/homebrew/opt/php@8.1/bin:$PATH"
export PATH="/opt/homebrew/opt/php@8.1/sbin:$PATH"

- パス適用

% source ~/.zshrc

- バージョン確認

% php -v         
PHP 8.1.15 (cli) (built: Feb  3 2023 12:35:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.15, Copyright (c), by Zend Technologies