🖥
Mac で Apache を起動して localhost にアクセスする
手順
ターミナルで以下を実行
sudo apachectl start
次に http://localhost/ にアクセスする
表示結果
停止
sudo apachectl stop
設定ファイル
ファイルの場所
/etc/apache2/httpd.conf
権限問題でファイル編集しづらいので、権限を変えておく
sudo chmod 606 httpd.conf
HTMLファイル
httpd.conf の DocumentRootを見ればHTMLなどファイルの場所が分かる
...
DocumentRoot "/Library/WebServer/Documents"
...
$ ls /Library/WebServer/Documents
./ ../ index.html.en
こちらも編集しやすいように権限を変えておく
sudo chmod 707 /Library/WebServer/Documents
sudo chmod 606 /Library/WebServer/Documents/*
ファイルの置き場を変える場合の例
httpd.conf を編集する
...
DocumentRoot "/Users/<あなたのMacユーザー名>/htdocs"
<Directory "/Users/<あなたのMacユーザー名>/htdocs">
...
ディレクトリとファイルを作成
mkdir /Users/<あなたのMacユーザー名>/htdocs
touch /Users/<あなたのMacユーザー名>/htdocs/index.html
Webサーバーを再起動する
sudo apachectl restart
参考
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2022-05-09
Discussion