1.前往文件夹/etc/apache2
2.打开apache2
文件夹下的httpd.conf
3.编辑文件以下文件内容并保存
找到
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
#
# 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 Multiviews
MultiviewsMatch Any
#
# 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
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
改成
DocumentRoot "/Users/username/Sites"
<Directory "/Users/username/Sites">
Require all granted
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
找到 #LoadModule php7_module libexec/apache2/libphp7.so 去掉前面的#
⚠️username是你的用户名,Sites是你的根目录名称,要手动创建。修改这个文件需要输入计算机开机密码。
4.使用命令行sudo apachectl start
启动apache
5.打开浏览输入localhost
或者172.0.0.1
即可访问你的文件