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
  • Use userdir see http://askubuntu.com/questions/388611/how-do-i-create-public-html-folder and https://joao.machado-family.com/2013/06/04/ubuntu-13-04-apache2-setup-public_html/ – Panther Dec 15 '16 at 19:23

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
  • 74,764
  • $#sudo a2ensite 000-default

    Site 000-default already enabled

    seems like it is already enabled.

    Didn't work

    – David Dec 15 '16 at 19:08
  • @David If it says that then run the restart command. If it's still not working, then disable the site, enable the site, and restart Apache. – Thomas Ward Dec 15 '16 at 19:10
  • Still did not work. All commands execute just fine, but it doesn't seem to have any effect – David Dec 15 '16 at 19:15
  • 1
    Use https://joao.machado-family.com/2013/06/04/ubuntu-13-04-apache2-setup-public_html/ – Panther Dec 15 '16 at 19:23
  • why disable the conf file then enable the conf file? is it not possible to enable it without disabling it? – barlop Dec 27 '20 at 23:19
  • You write "Apache ignores sites-available until you enable the site (in which case it symlinks it in sites-enabled)." <----- Not really accurate.. apache2.conf has a line that loads *.conf from the sites-enabled directory. Also, 000-default.conf is enabled by default. so is in sites-enabled by default. sites-enabled has a subset of the conf files from the sites-available directory, but as symlinks, and by default(fresh apache installation) has the 000-default.conf file sym-linked and just that Still a helpful answer though in that the commands are useful – barlop Jan 04 '21 at 19:21
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
  • 114,770
milegrin
  • 351
0
<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
  • 1
  • As written this makes no sense. What are these commands where do I need to enter them? Please edit the answer so it works. – David Apr 08 '23 at 08:27
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