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

Macbook M1 Chip Homebrew設置

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

Macbookを利用してApache, PHP, MySQLなどのパッケージ設置する際にパッケージ管理するHomebrewを使用すると簡単に管理ができます。

Homebrewを設置する方法について

 1. Macbookのタミナール「 brew -v 」入力 ( 以下になるとhomebrewが設定されてない状態)

% brew -v
zsh: command not found: brew

2.  以下のコードでパッケージ管理設定

参考)https://brew.sh/index_ja

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:     <= Mac管理者パスワード入力
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
..
/opt/homebrew/Frameworks

Press RETURN/ENTER to continue or any other key to abort:      <= Enter key
==> /usr/bin/sudo /usr/bin/install -d -o root -g wheel -m 0755 /opt/homebrew
==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
..
==> /usr/bin/sudo /usr/sbin/chown -R xxxx /Users/xxxx/Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 222453, done.
remote: Counting objects: 100% (334/334), done.
remote: Compressing objects: 100% (226/226), done.
remote: Total 222453 (delta 155), reused 246 (delta 95), pack-reused 222119
Receiving objects: 100% (222453/222453), 63.14 MiB | 7.56 MiB/s, done.
Resolving deltas: 100% (163653/163653), done.
From https://github.com/Homebrew/brew
 * [new branch]          less-agressive-core-tap -> origin/less-agressive-core-tap
 * [new branch]          master                  -> origin/master
 * [new branch]          setup-homebrew-test     -> origin/setup-homebrew-test
 * [new tag]             0.1                     -> 0.1
 * [new tag]             0.2                     -> 0.2
 ..
 ..
 * [new tag]             0.9.9                   -> 0.9.9
 * [new tag]             1.0.0                   -> 1.0.0
 * [new tag]             1.0.1                   -> 1.0.1
 ..
 ..
 * [new tag]             1.9.3                   -> 1.9.3
 * [new tag]             2.0.0                   -> 2.0.0
 * [new tag]             2.0.1                   -> 2.0.1
 ..
 ..
 * [new tag]             2.7.7                   -> 2.7.7
 * [new tag]             3.0.0                   -> 3.0.0
 * [new tag]             3.0.1                   -> 3.0.1
 ..
 ..
 * [new tag]             3.6.8                   -> 3.6.8
 * [new tag]             3.6.9                   -> 3.6.9
HEAD is now at b55f1dafe Merge pull request #14302 from p-linnane/improve-sparke-audit
==> Tapping homebrew/core
remote: Enumerating objects: 1383698, done.
remote: Counting objects: 100% (584/584), done.
remote: Compressing objects: 100% (274/274), done.
remote: Total 1383698 (delta 353), reused 524 (delta 310), pack-reused 1383114
Receiving objects: 100% (1383698/1383698), 528.19 MiB | 6.83 MiB/s, done.
Resolving deltas: 100% (963492/963492), done.
From https://github.com/Homebrew/homebrew-core
 * [new branch]              master     -> origin/master
HEAD is now at bcde3f1b57c kotlin: update 1.8.0 bottle.
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> 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 these three commands in your terminal to add Homebrew to your PATH:
    echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/xxxx/.zprofile    <=== 実行
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxxx/.zprofile   <=== 実行
    eval "$(/opt/homebrew/bin/brew shellenv)"                                   <=== 実行
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

- brewバージョン確認

% brew -v
zsh: command not found: brew

もしバージョンが表示されなければ、パスを通す必要があります。
Appleシリコン搭載のMacを使っている場合は、以下のコマンドを実行してください。

$ echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxxxxx/.zprofile
$ eval "$(/opt/homebrew/bin/brew shellenv)"

% brew -v
Homebrew 3.6.16
Homebrew/homebrew-core (git revision bcde3f1b57c; last commit 2022-12-29)

HomebrewでApache設置

- 設置可能な「httpd」確認

 % brew search httpd
==> Formulae
darkhttpd       httpd           httpdiff        libmicrohttpd   lighttpd        mighttpd2       httpx           httpry          httpie          httm

- 設置可能なバージョン確認

 % brew info httpd
==> httpd: stable 2.4.54 (bottled)
Apache HTTP server
https://httpd.apache.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/httpd.rb
License: Apache-2.0
==> Dependencies
Required: apr ✔, apr-util ✔, brotli ✔, libnghttp2 ✔, openssl@1.1 ✔, pcre2 ✔
==> Caveats
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.

To restart httpd after an upgrade:
  brew services restart httpd
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
==> Analytics
install: 18,091 (30 days), 57,999 (90 days), 376,770 (365 days)
install-on-request: 13,550 (30 days), 48,244 (90 days), 283,382 (365 days)
build-error: 61 (30 days)

- Apacheのインストール

 % brew install httpd

Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/services).
==> New Formulae
aptos                  cascadia               openvino               quartz-wm              twm                    xmodmap                xrdb
bzip3                  kwctl                  podsync                simdutf                xinit                  xorg-server

You have 4 outdated formulae installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

==> Fetching dependencies for httpd: ca-certificates
==> Fetching ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2023-01-10
######################################################################## 100.0%
..
==> Installing httpd
==> Pouring httpd--2.4.54_1.arm64_ventura.bottle.1.tar.gz
==> Caveats
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.

To restart httpd after an upgrade:
  brew services restart httpd
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND

- 設置バージョン確認

% httpd -v
Server version: Apache/2.4.54 (Unix)
Server built:   Sep 30 2022 02:51:01

- Apacheサービス起動 & 再起動

% brew services start httpd
% brew services restart httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)

- Apacheサービス停止

% brew services stop httpd   
Stopping `httpd`... (might take a while)
==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd)