$ brew install httpd
httpd.conf)/usr/local/etc/httpd/httpd.conf
httpd.confを設定すれば良い。 /etc/apache2/httpd.confは、MacにプリインストールされているApacheの設定ファイルなので間違えない。 brew install httpdでインストールした設定ファイルは、/usr/local/etc/httpd/httpd.conf。/usr/local/etc/httpd/extra/httpd-vhosts.confでバーチャルホストごとに設定する。
設定は、アクセスログをCustomLogディレクティブ、エラーログをErrorLogディレクティブに指定する。
設定例)/usr/local/etc/httpd/extra/httpd-vhosts.conf
ErrorLog "/usr/local/var/log/httpd/sample.local-error_log"
CustomLog "/usr/local/var/log/httpd/sample.local-access_log" common
Homebrewでインストールしたapache2のログ関連ファイルは、慣例として/usr/local/var/log/httpd以下に配置。
/usr/local/etc/httpd/httpd.confに以下の行を追加する。
libphp7.soのパスは、$ which phpで調べた。
+ LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so // if PHP 7.2
+ # LoadModule php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so // if PHP 7.3
+ <IfModule php7_module>
+ AddType application/x-httpd-php .php
+ </IfModule>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
ref.
ファイル名を指定していないアクセスに対して表示するファイルを指定。
以下の指定では、index.html -> index.phpの順で探索する。
<IfModule dir_module>
+ DirectoryIndex index.html index.php
- DirectoryIndex index.html
</IfModule>
/usr/local/etc/httpd/httpd.confを以下のように修正。
- # LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
+ LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
/usr/local/etc/httpd/httpd.confのVirtual hostsのコメントアウトを解除。
# Virtual hosts
- # Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
+ Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
/usr/local/etc/httpd/extra/httpd-vhosts.confにVirtual hostsを設定。
以下は名前ベース(ServerName)の指定例。
名前ベースのVirtual hostsでは、アクセスしたホストとServerNameが一致する設定が適用される。httpd-vhosts.confに一致する設定がない場合は、httpd.confの設定が適用される。
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/var/www/htmlc/example.com"
ServerName example.com
ServerAlias www.example.com
ErrorLog "/var/log/httpd/example.com-error_log"
CustomLog "/var/log/httpd/example.com-access_log" common
<Directory "/var/www/html/example.com">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
# AllowOverride None
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
</VirtualHost>
Options indexes FollowSymLinksのindexesを削除。
ref.
/private/etc/hostsに以下を追加(ドメインがexmaple.comの場合)。
127.0.0.1 example.com
brewでインストールした場合は、下記コマンドで実行可能
sudo brew services start httpdsudo brew services stop httpdsudo brew services restart httpd