LoginSignup
24

More than 5 years have passed since last update.

Homebrew で Apache 2.4 + PHP 7.0 環境を作る

Posted at

OS X El Capitan でやりました。

デフォルト Apache を止める

プリインストールされている Apache が起動してしまうと困るので止める

$ sudo apacehctl stop
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Apache 2.4 を入れる

brew install php70 --with-apache だけでも勝手に http24 がインストールされるのだけど、オプション付きでインストールしたいのであらかじめ入れておく。

$ brew options httpd24
--with-privileged-ports
    Use the default ports 80 and 443 (which require root privileges), instead of 8080 and 8443

オプションなしでインストールするとポート 8080 で起動するが、 --with-privileged-ports でインストールすることでポート 80 で起動させることができる。

$ brew install httpd24 --with-privileged-ports

PHP 7.0 を入れる

$ brew options php70
--with-apache
    Enable building of shared Apache 2.4 Handler module

--with-apache というオプションを付けると libphp7.so をビルドしてくれる。

$ brew install php70 --with-apache

httpd.conf を編集

php7_module が有効になっているか確認

/usr/local/etc/apache2/2.4/httpd.conf
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so

以下の行を追加

/usr/local/etc/apache2/2.4/httpd.conf
<IfModule php7_module>
  AddType application/x-httpd-php .php
</IfModule>

起動

$ sudo apachectl start

補足

apachectl status がコケる場合

$ sudo apachectl status
/usr/local/bin/apachectl: line 95: lynx: command not found

lynx は CUI の Web ブラウザらしい。
Apache が起動してるかどうかの確認に使っていると思われる。

$ brew install lynx
()

lynx を入れれば動く。

Composer を使う場合

mcrypt を入れておく

$ brew install php70-mcrypt

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
24