4

So I'm trying to change the DocumentRoot of my apache, but for some strange reason it just seems to ignore the file /etc/apache2/sites-available/00-default.conf

This is the content of the file:

<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 webroot@localhost
    DocumentRoot /home/david/www


    <Directory /home/david/www>
        Options Indexes
            Require all granted
    </Directory>
    # 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
David
  • 41

4 Answers4

13

Apache ignores sites-available until you enable the site (in which case it symlinks it in sites-enabled).

Run the following commands:

sudo a2dissite 000-default
sudo a2ensite 000-default
sudo systemctl restart apache2

This will disable the "Default" site, enable the "Default" site, and then the restart of Apache will refresh the configuration and should then use the updated docroot accordingly. Note there may be other permissions issues not discussed here; you would need to open a new question for that.

Thomas Ward
  • 78,878
2

None of the above solutions worked for me. No matter what I tried I could not get the default site to load including copying the config from my 14.04 VPS where it is working 100% (I am upgrading to 18.04).

In the end adding a VirtualHost for the local server name to my apache2.conf forcing it to be the first VirtualHost defined worked. It's not my preferred solution, but it worked:

<VirtualHost webserver.mydomain.za:80>
  ServerAdmin   webmaster@mydomain.za
  ServerName    webserver.mydomain.za
  DocumentRoot  /var/www/nowebsite
  ErrorLog      ${APACHE_LOG_DIR}/error.log
  CustomLog     ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>`

Strangely enough, the default SSL site worked the first time.

karel
  • 122,292
  • 133
  • 301
  • 332
milegrin
  • 421
1
<VirtualHost *:80>

  ServerAdmin webmaster@localhost
  DocumentRoot /home/david/www

  <Directory /home/david/www>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

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

</VirtualHost>

sudo systemctl restart apache2

You should remove all the code and put 1st code sample in your Apache Configuration file which is 000-default.conf and available at /etc/apache2/sites-available/
second command will restart the apache web server. In addition I want to tell you that you should always put DocumentRoot at /var/www/html/

ViShU
  • 21
  • 4
0

Try removing.

<Directory /home/david/www>
    Options Indexes
        Require all granted
</Directory>

Example:

VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/david/www>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Reload apache.

CeFu
  • 569