【问题标题】:Apache, MySql, dan PHP on MacMac 上的 Apache、MySql 和 PHP
【发布时间】:2016-11-28 07:21:35
【问题描述】:

我正在按照本教程将我的 Mac 设置为 Web 服务器:https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/

但不幸的是,我被卡住了,如果我访问 http://localhost/~username/info.php 它可以正常工作,但是当我只访问时:http://localhost/info.php 它说禁止,知道如何解决这个问题吗?

编辑:

我想同时访问系统根和用户根
非常感谢

【问题讨论】:

  • 它可以工作,因为它位于您的主目录中,而不是服务器根目录中。
  • @jaysingkar,我尝试了你上面提到的链接,但仍然无法正常工作,如果我只访问 localhost 说禁止,但如果我输入 localhost/~username 它可以正常工作。
  • @user3573124 你想访问这两个网址吗?
  • 赞成归零。如果人们要对这个问题投反对票,请解释原因。

标签: php mysql macos apache webserver


【解决方案1】:

我认为要实现这一点,您需要激活并使用虚拟主机。
试试这个:
1)打开httpd.conf文件:

sudo nano /etc/apache2/httpd.conf

2) 查找后续行并取消注释:

# Virtual hosts

Include /private/etc/apache2/extra/httpd-vhosts.conf

3) 这将允许使用 httpd-vhosts.conf 文件,打开此文件以添加到 vhost。

sudo nano /etc/apache2/extra/httpd-vhosts.conf

4) 在文件开头添加以下代码。

<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>

【讨论】:

  • 通过运行此命令检查您的配置是否正确httpd -S
  • 我认为,我的设置不正确,它显示如下:警告:DocumentRoot [/Library/WebServer/Documents/Sites/] 不存在 AH00112:警告:DocumentRoot [/Users/username /Sites/] 不存在抱歉这个愚蠢的问题,如何解决这个问题?非常感谢
  • 检查两个目录是否存在。在[/Users/username/Sites/] 中,我认为您需要使用您的用户名而不是username。你也可以用/etc/apache2/extra/httpd-vhosts.conf文件的内容更新你的问题
  • 对不起,我忘记更改真实姓名的用户名。我更改了它,但仍然禁止访问(截图链接-postimg.org/image/ylhj1iirb)。以下是我的虚拟主机: # 匹配任何 块中的 ServerName 或 ServerAlias。 # ServerName localhost DocumentRoot /Library/WebServer/Documents/ DocumentRoot "/Users/soetjitro/Sites/" ServerName localhost
猜你喜欢
  • 2011-10-03
  • 2017-05-25
  • 2013-12-06
  • 2023-03-06
  • 2022-11-28
  • 2012-02-05
  • 2012-03-18
  • 2014-05-30
  • 1970-01-01
相关资源
最近更新 更多