LoginSignup
4
5

More than 5 years have passed since last update.

macのローカルでapacheが立ち上がらないときに確認するhttpd.confのsyntax check

Posted at

今年、新調したmacbookのローカルでapacheが立ち上がらなかったため、いろいろ調べたがツイッターのある方に助けてもらったので確認方法を残す

前提

  • macにapache、phpはインストールされている
  • apache内にユーザー単位のファイルが既に作られている
    • /etc/apache2/users/ユーザ名.conf
  • sudo apachectl startをしてもlocalhostが起動しない
  • プロセスが立ち上がっていない
    • ps aux | grep httpdで立ち上がっていないことを確認

確認方法

apacheのsyntax的な問題を確認
sudo apachectl configtest

実行すると私の場合は以下のように表示される

診断結果
<Directory "Users/kamo/Sites/">
httpd: Syntax error on line 511 of /private/etc/apache2/httpd.conf: Syntax error on line 16 of /private/etc/apache2/extra/httpd-userdir.conf: Syntax error on line 4 of /private/etc/apache2/users/kamo.conf: Expected </Directory> but saw </Directiory>

どうやら/private/etc/apache2/users/kamo.conf<Directory>の閉じタグの書き方が間違っていたみたいで、即修正

これで問題ないかと思うけど念のためにもう一度確認すると

診断結果
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using kamoui-MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
Syntax OK

syntax的にはOKみたいだけど、「ServerNameを決めてくれ」と警告が出ていたのでこれをhttpd.confにて直す

#を取るかlocalhostで指定する
- #ServerName www.example.com:80
+ ServerName localhost

これで問題ないだろうと思うが念のために最終確認

診断結果
Syntax OK

やっと問題が出ないようになったのでsudo apachectl restartをするとlocalhostのIt works!が表示されるようになった!

4
5
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
4
5