mac 環境設定 mavericksからYosemiteにupdateしたらapacheが動かない
そろそろYosemiteも落ち着いてきた頃かな?と思い、Yosemiteにupdateしました。
<目次>
Rubyがバージョンアップされたことによる影響を補正
そしたら、apacheが起動しない><。
設定ファイルとかいろいろ確認してみたけど原因がさっぱりわからず、途方に暮れている時に救世主現る。
とにかくhomebrewを確認してみる。
たしかにbrewコマンドで同様のエラーが出た。
$ brew update
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
Rubyのバージョンを確認。
$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
参考サイトのまま変更
$ vi /usr/local/Library/brew.rb
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
↓
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0
修正後にbrewコマンドを実行して同じエラーが出ることを確認。
$ brew update
error: Your local changes to the following files would be overwritten by merge:
Library/brew.rb
Please, commit your changes or stash them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
gitにコミットします。
ステータスの確認。
$ cd /usr/local
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Library/brew.rb
no changes added to commit (use "git add" and/or "git commit -a")
ステージしてコミット
$ git add Library/brew.rb
$ git commit -m 'update ruby v2.0'
[master 286ce29] update ruby v2.0
1 file changed, 3 insertions(+), 1 deletion(-)
で、brew updateしたら今度はパーミッションが通ってないって?!
$ brew update
error: unable to unlink old '.gitignore' (Permission denied)
error: unable to create file .yardopts (Permission denied)
error: unable to create file CODEOFCONDUCT.md (Permission denied)
error: unable to unlink old 'CONTRIBUTING.md' (Permission denied)
error: unable to create file LICENSE.txt (Permission denied)
error: unable to unlink old 'README.md' (Permission denied)
error: unable to unlink old 'SUPPORTERS.md' (Permission denied)
Warning: Could not tap homebrew/dupes/apr-util over Homebrew/homebrew/apr-util
Warning: Could not tap homebrew/dupes/apr over Homebrew/homebrew/apr
Warning: Could not tap homebrew/dupes/fetchmail over Homebrew/homebrew/fetchmail
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
これは上記参考サイトには載ってないよ!!
/usr/local のパーミッション変更
今度はこちらを参考に。
まずは権限の確認。
$ cd /usr/local
$ ls -al
total 72
drwxr-xr-x 18 root wheel 612 7 2 11:35 .
drwxr-xr-x@ 12 root wheel 408 7 2 13:30 ..
・・・
パーミッションが「755」で、グループが「wheel」になってることを確認。
パーミッションを「775」、グループを「staff」に変更。
$ cd `brew --prefix`
$ sudo chgrp staff .
$ sudo chmod 775 .
$ git fetch origin
$ git reset origin/master --hard
で、brew update。
今度は無事OK!!
これでようやくapacheを起動できる!と思ったのですが、
$ sudo apachectl start
で反応なし。
一応確認。
username 554 0.0 0.0 2441988 660 s000 S+ 9:39PM 0:00.00 grep httpd
やっぱり動いてない。
apacheのエラーログ(/usr/local/var/apache2/log/error_log)を確認。
[Thu Jul 02 21:39:21 2015] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Thu Jul 02 21:39:21 2015] [error] (2)No such file or directory: Couldn't bind unix domain socket /usr/local/var/apache2/run/cgisock.551
[Thu Jul 02 21:39:22 2015] [notice] Digest: generating secret for digest authentication ...
[Thu Jul 02 21:39:22 2015] [notice] Digest: done
[Thu Jul 02 21:39:22 2015] [error] (2)No such file or directory: could not create /usr/local/var/apache2/run/httpd.pid
[Thu Jul 02 21:39:22 2015] [error] httpd: could not log pid to file /usr/local/var/apache2/run/httpd.pid
なんかよくわからなくなってきたので、apacheを入れ直すことに!
apacheとPHPをhomebrewでインストールしなおす
設定ファイル(/usr/local/etc/apache2
)をコピーしてバックアップしておきます。
brewでapacheをアンインストール&設定ファイル削除。
$ brew uninstall httpd
Uninstalling /usr/local/Cellar/httpd/2.2.26... (1311 files, 21M)
$ rm -rf /usr/local/etc/apache2
brewをupdate
$ brew update
$ brew tap homebrew/dupes
$ brew tap homebrew/apache
$ brew install httpd22
無事インストール完了。
確認。
$ which apachectl
/usr/local/bin/apachectl
$ apachectl -v
Server version: Apache/2.2.29 (Unix)
Server built: Jul 2 2015 22:08:24
設定ファイルを編集して
$ sudo apachectl start
httpd: Syntax error on line 118 of /usr/local/etc/apache2/2.2/httpd.conf: Cannot load /usr/local/opt/php54/libexec/apache2/libphp5.so into server: dlopen(/usr/local/opt/php54/libexec/apache2/libphp5.so, 10): Library not loaded: /usr/local/lib/libaprutil-1.0.5.2.dylib\n Referenced from: /usr/local/opt/php54/libexec/apache2/libphp5.so\n Reason: image not found
もう!ヤになっちゃう!!!
phpも入れ直そう!
phpのバージョンを確認。
$ brew list
phpとをアンインストールして設定ファイルを削除(バックアップを取ってからね)。
$ brew uninstall php54
Uninstalling /usr/local/Cellar/php54/5.4.24... (488 files, 37M)
$ rm -rf /usr/local/etc/php
phpをインストール。
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php
$ brew search php
前回同様、PHP5.4をMySQLとtidyのオプションをつけてインストールします。
$ brew install homebrew/php/php54 --with-mysql --with-tidy --homebrew-apxs
--homebrew-apxs はapacheへの自動設定を行ってくれるそうです。
インストール完了!
apache起動。
$ sudo apachectl start
$ ps aux | grep httpd
daemon 49891 0.0 0.0 2480412 792 ?? S 11:06PM 0:00.00 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
daemon 49890 0.0 0.0 2472220 800 ?? S 11:06PM 0:00.00 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
daemon 49889 0.0 0.0 2480412 796 ?? S 11:06PM 0:00.00 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
daemon 49888 0.0 0.0 2480412 792 ?? S 11:06PM 0:00.00 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
daemon 49887 0.0 0.0 2480412 796 ?? S 11:06PM 0:00.00 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
daemon 49886 0.0 0.0 2461316 784 ?? S 11:06PM 0:00.00 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
root 49885 0.0 0.2 2472220 7156 ?? Ss 11:06PM 0:00.04 /usr/local/Cellar/httpd22/2.2.29/bin/httpd -k start
username 49893 0.0 0.0 2432772 648 s000 S+ 11:07PM 0:00.00 grep httpd
やれやれ^^
無事 http://localhost に接続できました。
apacheの自動起動設定
plistファイルにシンボリックリンクを貼る。
launchctlにロードしてサービスを登録する。
$ sudo ln -sfv /usr/local/opt/httpd22/*.plist /Library/LaunchDaemons$ sudo chmod 600 ~/Library/LaunchAgents/homebrew.mxcl.httpd22.plist
$ sudo chown root ~/Library/LaunchAgents/homebrew.mxcl.httpd22.plist
$ sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.httpd22.plist
~/Library/LaunchAgents にシンボリックリンクを置いても自動起動しませんでした><。
ちなみに・・
Yosemiteに標準で入ってるapacheの自動起動を停止する方法。
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
OSのupdateってホント面倒くさい><。
けど、この苦難を乗り越えたら良いこといっぱいありそう♪