Mac OS Brew安装apache配置虚拟主机

2022-03-30  本文已影响0人  无疆wj

mac os 10.15.7

// 内置的apache
// 停用
sudo apachectl stop
// 禁止开机启动
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
//安装
brew install httpd
# /usr/local/etc/httpd/httpd.conf
...
Listen 80
...
ServerName www.example.com:80
...
#引入自定义虚拟主机配置文件
Include /usr/local/etc/httpd/vhosts/*.conf
#配置虚拟主机
<VirtualHost *:80>
    DocumentRoot "***/a.test"
    ServerName "a.test"
    ServerAlias "www.a.test"
    <Directory "***/a.test">
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

#监听端口(局域网访问)
Listen 9000
<VirtualHost *:9000>
    DocumentRoot "***/a.test"
    ServerName "a.test"
    ServerAlias "www.a.test"
    <Directory "***/a.test">
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>
//host
127.0.0.1 a.test
127.0.0.1 www.a.test

访问
http://a.test
http://127.0.0.1:9000

配置php支持

# /usr/local/etc/httpd/httpd.conf
...
LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so
...
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
上一篇下一篇

猜你喜欢

热点阅读