【问题标题】:why is it that info.php only work if placed in /var/www/html not /var/www/?为什么 info.php 只有放在 /var/www/html 而不是 /var/www/ 时才有效?
【发布时间】:2016-01-15 01:54:20
【问题描述】:

我刚刚部署了 LAMP 以准备安装 Elgg。在我部署了 apache 和 php 之后,我想通过创建 info.php 文件来测试我的进度。我将文件放在 /var/www/ 并尝试从浏览器访问它,结果却报错:

Not Found

The requested URL /info.php was not found on this server.

Apache/2.4.7 (Ubuntu) Server at 192.168.0.9 Port 80

当我在 /var/www/html 中放置相同的文件时,它工作并显示了 Apache 和 php 安装设置。谁能向我解释为什么?用于教育目的。

【问题讨论】:

  • 因为默认情况下/var/www/html 是默认的文档根目录。如果您只想使用 /var/www/,则必须更改 httpd.conf
  • 您的配置文件夹的根目录为DocumentRoot 。在我位于httpd.conf 中的服务器上/etc/httpd/conf/

标签: php apache


【解决方案1】:

Apache 网络服务器将显示放置到特定位置的文档。该位置的根称为文档根。

例如,如果 DocumentRoot 设置为 /var/www/html,则对 http://www.yoursite.com/folder1/yourpage.php 的请求将导致文件 /var/www/html/folder1/yourpage.php 被提供给请求客户端

在 ubuntu 中默认位置是 /var/www 用于服务器根目录,而在 Centos 上默认位置是 /var/www/html

此更改需要重新启动服务。

您可以从/etc/httpd.conf 更改它,其中有一个关于文档根目录的部分。

但再次在你的发行版上,它是 ubuntu,它在 /etc/apache2/http.conf

基于 Debian 的系统

ServerRoot              ::      /etc/apache2
DocumentRoot            ::      /var/www
Apache Config Files     ::      /etc/apache2/apache2.conf
                        ::      /etc/apache2/ports.conf
Default VHost Config    ::      /etc/apache2/sites-available/default,/etc/apache2/sites-enabled/000-default
Module Locations        ::      /etc/apache2/mods-available, /etc/apache2/mods-enabled
ErrorLog                ::      /var/log/apache2/error.log
AccessLog               ::      /var/log/apache2/access.log
cgi-bin                 ::      /usr/lib/cgi-bin
binaries (apachectl)    ::      /usr/sbin
start/stop              ::      /etc/init.d/apache2 (start|stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean)

【讨论】:

  • 我在这个位置找不到 http.config?
  • 其实Ubuntu中不存在这个文件wiki.apache.org/httpd/…:
  • 这是一个参考链接,你可以去看看。我也在回答这个问题
  • 找到了,修改文档根目录需要在/etc/apache2/apache2.conf中进行修改
【解决方案2】:

因为/var/www/html 是您的apache 的默认文档根路径。 您可以在/etc/apache2/sites-available/default.conf 中编辑路径。您可以。找到 DocumentRoot 为

/var/www/html

【讨论】:

  • 我在这两个位置都找不到 http.config?
【解决方案3】:

apache 的默认 DocumentRoot 是 /var/www/html。编辑位于/etc/apache2 目录中的 httpd.conf 配置文件并将 DocumentRoot 更改为 /var/www

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 2022-01-09
    • 2011-09-13
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2017-02-28
    相关资源
    最近更新 更多