Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need "/var/www" but Apache2 try to use an empty "/var/www/html"

This days I sleep with my http://localhost working, and reading pages from /var/www...

I woke up with an "AH00094" error at Apache2 log, and (Apache2 created?) a surprised /var/www/html, that Apache2 try to use.

Now my http://localhost/anything not works (error 404 at browser).

How to fix it? I need back my http://localhost working with files at /var/www!

Context

I am using Ubuntu12 with Apache2, all default and standard.

I checked out error log by tail /var/log/apache2/error.log in order to find out exact path that Apache, that shows

 ... [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

The folder /var/www/html is new, all, like '/var/www/info.php', are at /var/www, not at /var/www/html.

I fixed the "AH00094" error editing

 sudo nano /etc/apache2/apache2.conf

and adding at last line

 ServerName localhost

(now no log errors about localhost, but nothing works)

PS: I checked other related issues, but not is the same problem: Permissions for /var/www/html , Attempting to use symbolic link for var/www/html


I'm afraid to use the clues of this answer ... in my Ubuntu there are no the .conf indicated files. I must create it? Is secure?


As @RahilWazir suggested, here is also my "/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
like image 745
Peter Krauss Avatar asked Feb 17 '14 14:02

Peter Krauss


2 Answers

See here:

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

The default directory apparently (we were also surprised) moved from /var/www to /var/www/html for htdocs in Debian, and Ubuntu copied this change. The reasons given are somewhat sound, but the upgrade path is probably “interesting” (as in the Chinese proverb)… as you have encountered.

like image 75
mirabilos Avatar answered Sep 24 '22 00:09

mirabilos


If you want to use /www as root folder instead of /www/html you can simply edit the apache2 config file to have /var/www

Edit 000-default.conf

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

then change

DocumentRoot /var/www/html 

to

DocumentRoot /var/www

Restart apache2 server :

sudo service apache2 restart
like image 36
user2997418 Avatar answered Sep 26 '22 00:09

user2997418