mac os下使用XAMPP开启Apache时, 使用localhost显示403错误解决办法

安装完xampp后,想添加一个virsualhost,一直报错。查了半天资料,都是乱说,后来看到了一篇国外的文章,终于弄出来了,整理一下。

第一步,配置本地hosts

sudo vi /etc/hosts

在后面添加你的域名xxx.com

127.0.0.1 xxx.com

第二步 启用apache的虚拟主机功能

打开配置文件 vi /Applications/XAMPP/xamppfiles/etc/httpd.conf

找到下面这一行,去掉最前面的#

Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

第三步 配置虚拟主机

首先打开配置文件 vi /Applications/XAMPP/etc/extra/httpd-vhosts.conf

清空里面的内容,因为是新安装的,不清空也可以

先把localhost的virsualhost配置一下,不然会出错,一般都是卡在这里了。我的网站编辑器有问题,查看页面源码可以看到配置文件。

默认虚拟主机

<virtualhost *:80>

    ServerName localhost

    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"

    <directory "/Applications/XAMPP/xamppfiles/htdocs">

   Options Indexes FollowSymLinks Includes execCGI

   AllowOverride All

   Require all granted

</directory>

</virtualhost>

然后添加自己的虚拟主机

<virtualhost *:80>

ServerName mysite.local

DocumentRoot "/Users/yourusername/path/to/your/site"

<directory "/Users/yourusername/path/to/your/site">

    Options Indexes FollowSymLinks Includes ExecCGI

    AllowOverride All

    Require all granted

</directory>

ErrorLog "logs/mysite.local-error_log"

</virtualhost>

第四步 如果经过以上步骤重启apache还是有403错误, 就找到/Applications/XAMPP/xamppfiles/etc/httpd.conf

修改里面的User和Group, User修改为你的电脑的用户名, group修改为staff

也就是

User daemon

User mac

Group daemon

Group staff

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

推荐阅读更多精彩内容