Mac本地Apache开启VirtualHost

Mac环境的php开发环境搭建推荐另一篇文章
这里仅作记录备忘一下。

Mac自带Apache服务,配置文件在/etc/apache2/httpd.conf

把默认的下面两行注释放开

1
2
LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf

.
修改默认目录,默认目录在/Library/WebServer/Documents下:

1
2
#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/yiny/Sites"

添加如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<Directory "/Users/yiny/Sites">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

<VirtualHost *:80>
ServerName sjdt.online.test
DocumentRoot "/Users/yiny/Sites/sjdt.online"
DirectoryIndex index.html index.php
<Directory "/Users/yiny/Sites/sjdt.online">
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

启动停止命令:

1
2
3
4
5
6
7
8
# 启动
sudo systemctl start

# 停止
sudo systemctl stop

# 重启
sudo systemctl restart

Mac本地安装配置PHP

安装php

1
brew install php
1
brew services start php

php.ini 配置文件位置:

1
/usr/local/etc/php/7.4