Mac/インストール/apache/brew
提供: 初心者エンジニアの簡易メモ
目次
インストール
brew install httpd
設定
vi /opt/homebrew/etc/httpd/httpd.conf
操作
起動
brew services start httpd
停止
brew services stop httpd
再起動
brew services restart httpd
http表示
デフォが8080ポートになってる。
http://localhost:8080
8080と80両方でアクセスする場合は、Listen 80を、追加する。
Listen 8080 Listen 80
デフォルトのドキュメントルート
/opt/homebrew/var/www
brewで入れたphpを有効にしたい場合
/opt/homebrew/etc/httpd/httpd.confに以下を追加
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
- <IfModule dir_module> - DirectoryIndex index.html - </IfModule> + <IfModule dir_module> + DirectoryIndex index.php index.html + </IfModule>
/opt/homebrew/etc/httpd/httpd.confの最下に追加
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
サブドメインを有効に
コメントを解除
$ vi /opt/homebrew/etc/httpd/ - #Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf + Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
コピーしてカスタマイズする
$ cp /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf /opt/homebrew/etc/httpd/extra/test.conf $ vi /opt/homebrew/etc/httpd/httpd.conf Include opt/homebrew/etc/httpd/extra/test.conf
httpd-vhosts.confの初期文字列
<VirtualHost *:8080>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/opt/homebrew/opt/httpd/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/opt/homebrew/var/log/httpd/dummy-host.example.com-error_log"
CustomLog "/opt/homebrew/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/opt/homebrew/opt/httpd/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/opt/homebrew/var/log/httpd/dummy-host2.example.com-error_log"
CustomLog "/opt/homebrew/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>
サブドメインtest例
test.localhostと、test.example.comでアクセスできるように。
<VirtualHost *:80>
DocumentRoot "/var/www/laravel/test/public"
ServerName test.localhost
ErrorLog "/opt/homebrew/var/log/httpd/test.localhost-error_log"
CustomLog "/opt/homebrew/var/log/httpd/test.localhost-access_log" common
<Directory "/var/www/laravel/test/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/laravel/test/public"
ServerName test.example.com
ErrorLog "/opt/homebrew/var/log/httpd/test.localhost-error_log"
CustomLog "/opt/homebrew/var/log/httpd/test.localhost-access_log" common
<Directory "/var/www/laravel/test/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
RewriteEngineエラーになるとき
エラー詳細
.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
httpd.confのmod_rewriteのコメントアウトを外す。
- # LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so + LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
client deniedエラーになるとき
エラー詳細
AH01630: client denied by server configuration:
許可するdirを追加する
<Directory "/d/www/laravel/test/public">
AllowOverride All
Require all granted
</Directory>
