我需要“/ var / www”但是Apache2尝试使用空的“/ var / www / html”

时间:2014-02-17 14:10:29

标签: apache2 directory

这一天,我在http://localhost工作时睡觉,并从/var/www阅读页面......

我在Apache2日志中发现了“AH00094”错误,并且(Apache2创建了?)一个惊讶的/var/www/html,Apache2尝试使用。

现在我的http://localhost/anything无效(浏览器错误404)。

如何修复?我需要让我的http://localhost使用/var/www处的文件进行操作!

上下文

我正在使用Ubuntu12和Apache2,所有默认和标准。

我通过tail /var/log/apache2/error.log检查了错误日志,以找出Apache显示的确切路径

 ... [core:notice] [pid 1597] AH00094: Command line: '/usr/sbin/apache2'
 ... [:error] [pid 1604] [client 127.0.0.1:40624] script '/var/www/html/info.php' not found or unable to stat

文件夹/var/www/html是新的,全部,如'/var/www/info.php',位于/var/www,而不是/var/www/html

fixed the "AH00094" error正在编辑

 sudo nano /etc/apache2/apache2.conf

并在最后一行添加

 ServerName localhost

(现在没有关于localhost的日志错误,但没有任何作用)

PS:我检查了其他相关问题,但不是同一个问题:Permissions for /var/www/htmlAttempting to use symbolic link for var/www/html


我害怕使用clues of this answer ...在我的Ubuntu中没有.conf指示的文件。我必须创造它吗?安全吗?


正如@RahilWazir建议的那样,这里也是我的“/etc/apache2/sites-available/000-default.conf”,

  <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
  </VirtualHost>

  # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

2 个答案:

答案 0 :(得分:9)

见这里:

Why has the apache2 www dir been moved to /var/www/html?

对于Debian中的htdocs,默认目录显然(我们也很惊讶)从/var/www移动到/var/www/html,Ubuntu复制了这个更改。给出的理由有些合理,但升级路径可能“有趣”(如中国谚语中)......正如您所遇到的那样。

答案 1 :(得分:2)

如果您想使用/www作为根文件夹而不是/www/html,您只需编辑apache2配置文件即可拥有/ var / www

编辑000-default.conf

sudo gedit /etc/apache2/sites-available/000-default.conf

然后改变

DocumentRoot /var/www/html 

DocumentRoot /var/www

重启apache2服务器:

sudo service apache2 restart