LoginSignup
2
2

More than 1 year has passed since last update.

はじめての記事投稿

【MAMP】環境構築やってみた!

Last updated at Posted at 2023-06-10

:hatching_chick: 新MacBookProを手に入れたので、MAMP環境を構築してみた!!

Homebrew

1. Homebrewのインストール

(1) HomebrewのWebサイトを表示
スクリーンショット 2023-06-08 19.37.53.png

(2) トップページに表示しているコマンドをコピー

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 
(3) ターミナルを起動して、(2)でコピーしたコマンドを貼り付けて実行

 ① パスワードを入力してReturn

hoge@MacbookPro ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:

 
 ② インストールするスクリプトと作られるディレクトリをずらずらと表示した後、
   Return を押すよう求められるので、Return を押す

︙
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks

Press RETURN/ENTER to continue or any other key to abort:

 
 ③ インストールが続いて、
   「Installation successful!」とインストール成功を表示する

︙
 * [new tag]             4.0.8                                                   -> 4.0.8
 * [new tag]             4.0.9                                                   -> 4.0.9
HEAD is now at 322a0189c Merge pull request #15529 from carlocab/deps-fix
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!

2. Homebrewをインストールできているかを確認

(1) Homebrewのバージョンを確認する

brew -v

 
 →バージョンを表示したらインストールできている

Homebrew 4.0.21

 
 →次を表示したらパスが通っていないので、パスを通す

zsh: command not found: brew
  • パスを通すコマンド
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/ ●hoge● /.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

  ※ ●hoge● : ユーザーのディレクトリ名

MySQL

1. MySQLのインストール

※今回はバージョン5.7を指定してHomebrew経由でインストール

(1) Homebrewが提供しているMySQLのバージョンに5.7があるかを確認する

brew search mysql@5.7
==> Formulae
mysql@5.7        mysql@5.6

 
(2) MySQL5.7をインストールする

brew install mysql@5.7

2. インストールしたバージョンでパスを通す

(1) パスを通すコマンドを実行する

export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc'

3. MySQLをインストールできているかを確認

(1) MySQLのバージョンを確認する

mysql --version

 →バージョンを表示したらインストールできている

mysql  Ver 14.14 Distrib 5.7.42, for osx10.18 (x86_64) using  EditLine wrapper

4. MySQLを起動

(1) 起動するコマンドを実行する

brew services start mysql@5.7

 →次を表示したら起動成功

==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)

5. MySQLのセキュリティ設定

(1) セキュリティ設定するコマンドを実行

mysql_secure_installation

 
① VALIDATE PASSWORD プラグインをインストールするか問われるので、
  Yes もしくは y を入力してReturn

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

 
② パスワードの設定ポリシーを選択する

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 
  • LOW:8文字以上
  • MEDIUM:8文字以上 / 数字・アルファベットの大文字と小文字・特殊文字を含む
  • STRONG:8文字以上 / 数字・アルファベットの大文字と小文字・特殊文字を含む / 辞書ファイルでのチェック
     
    ③ 設定するパスワードを入力してReturn
Please set the password for root here.

New password: 

Re-enter new password: 

 
④ アノニマスユーザーを削除するかどうか問われる
 → y を入力してReturn
 →入力後、「Success.」と表示したらOK

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

 ※アノニマスユーザー(匿名ユーザー): MySQLインストール時に作成される、名前もパスワードも設定していないユーザー
 
⑤ リモートでrootユーザーでログインすることを許可しないか問われる
 → y を入力してReturn
 →入力後、「Success.」と表示したらOK

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

 
⑥ テストデータベースを削除するかどうかを問われる
 → y を入力してReturn
 →入力後、次を表示したらOK
  ・「Dropping test database...Success.」
  ・「Removing privileges on test database...Success.」

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

 
⑦ 権限テーブルを更新するかどうかを問われる
 → y を入力してReturn
 →入力後、「Success.」を表示したらOK

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

6. MySQLにログイン

(1) rootユーザーでログイン

mysql -uroot -p●hoge●

  ※ ●hoge● : 設定したrootユーザーのパスワード
 
(2) 次のコンソールを表示したらログイン成功

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.42 Homebrew

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

PHP

1. PHPのインストール

※Homebrew経由でインストール

(1) PHPをインストールする

brew install php

2. PHPをインストールできているかを確認

(1) PHPのバージョンを確認する

php -v

 →バージョンを表示したらインストールできている

PHP 8.2.6 (cli) (built: May 11 2023 12:51:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies

Apache

1. Apacheのインストール

※Homebrew経由でインストール

(1) ビルドインのApacheを停止する

sudo apachectl stop

(2) Apacheをインストール

brew install httpd

(3) Apacheをインストールできているかを確認する

brew info httpd

 →次の様にバージョンを表示したらインストール成功

=> httpd: stable 2.4.57 (bottled)      ⇦ これ
Apache HTTP server
https://httpd.apache.org/
/opt/homebrew/Cellar/httpd/2.4.57 (1,663 files, 32MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-06-15 at 19:32:53
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: 3,533 (30 days), 12,989 (90 days), 12,989 (365 days)
install-on-request: 3,261 (30 days), 12,162 (90 days), 12,162 (365 days)
build-error: 0 (30 days)

→結果いわく、設定ファイル等は下記になる

ディレクトリ・ファイルパス
ドキュメントルート /opt/homebrew/var/www
サーバ設定ファイル /opt/homebrew/etc/httpd/httpd.conf
SSL証明書設定ファイル /opt/homebrew/etc/httpd/extra/httpd-ssl.conf

 
(4) Apacheを起動する

brew services start httpd

 →次を表示したら起動成功

==> Successfully started `httpd` (label: homebrew.mxcl.httpd)

※ビルドインのものを起動する場合

1. 必要なものをインストールしているのかを確認

(1) Apache httpdをインストールしているかを確認する

which httpd

 →Apache httpdをインストールしているディレクトリパスを表示したら、インストールできている

/usr/sbin/httpd

 
(2) Apache httpdを起動/停止するコントローラ apachectlをインストールしているかを確認する

which apachectl 

 →apachectlをインストールしているディレクトリパスを表示したら、インストールできている

/usr/sbin/apachectl

2. Apacheを起動

(1) 管理者権限でApacheを起動するコマンドを実行する

sudo /usr/sbin/apachectl start

 
(2) Apacheを起動できているかを確認する
 ① ブラウザで http://localhost にアクセスする
 ② ブラウザ内のページで「It Works!」と表示したら起動できている
スクリーンショット 2023-06-10 18.57.29.png

※Apacheのバージョンを確認するには下記コマンドを実行

/usr/sbin/httpd -version

 
※Apacheを停止するには下記コマンドを実行

sudo /usr/sbin/apachectl stop
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2