Laradock 虚拟主机无法在 mac monterey apache2 上工作

发布于 2025-01-15 09:47:53 字数 1848 浏览 4 评论 0原文

我读过很多关于这个主题的文章,但没有一个提到我所拥有的完全相同的环境(Mac OS Monterey)。所以到目前为止我所做的...

我已经成功安装了最新版本的 Docker 和 Docker。 LaraDock 与 apache2。我的 phpMyAdmin 在 localhost:8081 上工作正常。然后我按照文档和一些教程为多项目设置 laradock。

我在工作区容器内成功创建了一个 laravel9 项目(ProjectA)。我可以在浏览器中查看该网站,地址为 localhost/ProjectA/public。

我想为 ProjectA 创建一个虚拟主机,以便能够在浏览器中键入 projectA.test 并指向 localhost/ProjectA/public。

因此,我再次按照 Laradock 上的说明编辑了 laradock/apache2/sites/default.apache.conf

<VirtualHost *:80>
  ServerName laradock.test
  DocumentRoot /var/www/
  Options Indexes FollowSymLinks

  <Directory "/Users/Sites">
    AllowOverride All
    <IfVersion < 2.4>
      Allow from all
    </IfVersion>
    <IfVersion >= 2.4>
      Require all granted
    </IfVersion>
  </Directory>

  ErrorLog /var/log/apache2/error.log
  CustomLog /var/log/apache2/access.log combined
</VirtualHost>

并创建了 laradock/sites/projectA.conf

<VirtualHost *:80>
  ServerName projectA.test
  DocumentRoot /var/www/projectA/public
  Options Indexes FollowSymLinks

  <Directory "/var/www/projectA/public">
    AllowOverride All
    <IfVersion < 2.4>
      Allow from all
    </IfVersion>
    <IfVersion >= 2.4>
      Require all granted
    </IfVersion>
  </Directory>

</VirtualHost>

即使在 Docker 中重新启动 apache2 后,projectA.test 也不会显示正确的网站,但指向根。

在 apache2 文件夹中,有一个名为 vhost.conf 的文件,其中包含 /etc/apache2/sites-available/*.conf。当我将上面的 2 个conf 文件复制到该文件夹​​(以前不存在)时,我收到“禁止”错误:您无权访问此资源。 Apache/2.4.29 (Ubuntu) 服务器位于 utopia.test 端口 80。

阅读有关 apache 错误 403 的文章后,我将公共文件夹的权限更改为:

sudo chmod -R 775 public
sudo chown -R _www:_www public

drwxrwxr-x@ 15 _www  _www      480 Mar 19 18:11 public

如果有人可以提供帮助,我将非常感激。

I have read many posts on the subject but none refers to exactly the same environment I have (Mac OS Monterey). So what I have done so far...

I have successfully installed the latest versions of Docker & LaraDock with apache2. I have phpMyAdmin working fine at localhost:8081. Then I followed the docs and some tutorial to set up laradock for multiproject.

I successfuly created a laravel9 project (ProjectA) inside the workspace container. I can view the website in the browser at localhost/ProjectA/public.

I want to create a virtual host for ProjectA to be able to type projectA.test in the browser and point to localhost/ProjectA/public.

So again, I followed the instructions on Laradock and edited the laradock/apache2/sites/default.apache.conf

<VirtualHost *:80>
  ServerName laradock.test
  DocumentRoot /var/www/
  Options Indexes FollowSymLinks

  <Directory "/Users/Sites">
    AllowOverride All
    <IfVersion < 2.4>
      Allow from all
    </IfVersion>
    <IfVersion >= 2.4>
      Require all granted
    </IfVersion>
  </Directory>

  ErrorLog /var/log/apache2/error.log
  CustomLog /var/log/apache2/access.log combined
</VirtualHost>

and created a laradock/sites/projectA.conf

<VirtualHost *:80>
  ServerName projectA.test
  DocumentRoot /var/www/projectA/public
  Options Indexes FollowSymLinks

  <Directory "/var/www/projectA/public">
    AllowOverride All
    <IfVersion < 2.4>
      Allow from all
    </IfVersion>
    <IfVersion >= 2.4>
      Require all granted
    </IfVersion>
  </Directory>

</VirtualHost>

Even after restarting apache2 in Docker, projectA.test does not display the correct website but point to the root.

In the folder apache2 there is a file called vhost.conf with Include /etc/apache2/sites-available/*.conf. When I copied the 2 conf files above into that folder (which was not there before), I get a Forbidden error : You don't have permission to access this resource. Apache/2.4.29 (Ubuntu) Server at utopia.test Port 80.

After reading an article on apache error 403, I change the permission on the public folder to be:

sudo chmod -R 775 public
sudo chown -R _www:_www public

drwxrwxr-x@ 15 _www  _www      480 Mar 19 18:11 public

I would really appreciate if someone could help please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人如初 2025-01-22 09:47:53

我对这个问题感到非常厌倦,以至于我忘记在更改权限后重新启动 Apache...这就是窍门!

我希望这对其他人有帮助,因为我在有关该主题的任何教程或帖子中都没有找到此解决方案!

I was so tired with this issue that I forgot to restart Apache after changing permission... that was the trick!

I hope this will help others as I did not find this solution in any of the tutorials or posts on the subject!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文