安装 Apache

安装命令

brew install httpd

启动命令

# 启动
sudo brew services start httpd
#重启
sudo brew services restart httpd

Apache 配置

配置文件位置

通过安装后的一些信息,可以发现目录位置及配置文件位置 :

==> Installing httpd
==> Pouring httpd--2.4.51.big_sur.bottle.tar.gz
# 默认站点目录
DocumentRoot is /usr/local/var/www.

# 安装目录位置及配置文件位置
/usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo

打开配置文件,修改 -> 保存 后重启 apache 访问使其生效即可。

开启伪静态

LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

虚拟主机配置示例

<VirtualHost *:80>
    DocumentRoot "/Users***/localhost"
    ServerName localhost
    ServerAlias www.localhost.com
    ErrorLog "/Users/***/logs/localhost/error_log"
    CustomLog "/Users/***/logs/localhost/access_log" combined
	<Directory "/Users/***/localhost">
	    AllowOverride All
	    Order allow,deny
	    Allow from all
	    Require all granted
		DirectoryIndex index.php index.html
	</Directory>
</VirtualHost>