Mac 配置Apache自定义目录

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即可访问你的文件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容