Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache doesn't use DocumentRoot after upgrading to Ubuntu 13.10 (Uses default page that says "It works!")

I have various virtual hosts for my web development work, including cnm. The

sites-available/cnm

my file says very simply:

<VirtualHost *:80>
    ServerName cnm
    DocumentRoot /var/www/cnm/public_html
</VirtualHost>

I upgraded to Ubuntu 13.10, and when I point my browser to cnm/, I see the /var/www/index.html file that seems to be indicated in the default file

sites-available/000-default.conf

which says (among other things):

<VirtualHost *:80>
    DocumentRoot /var/www

What do I need to do to get Apache to read my cnm document root when I browse to cnm/ ?

NOTES:

  1. I already tried renaming my sites-available/cnm file to sites-available/cnm.conf and enabling it with a2ensite cnm and service apache2 reload. That is a good thing, but it changes nothing.

  2. I already tried changing <VirtualHost *:80> to <VirtualHost cnm.localhost> or to <VirtualHost cnm>. That did nothing.

like image 704
Tom Haws Avatar asked Nov 07 '13 16:11

Tom Haws


People also ask

What is the default location of DocumentRoot?

In this article, we will learn how to change the Apache default web root folder to a new location. By default, the Apache web root or Document root folder location is at /var/www/html.

Where is DocumentRoot in Apache?

The DocumentRoot directive is set in your main server configuration file ( httpd. conf ) and, possibly, once per additional Virtual Host you create.

What is DocumentRoot in Apache server?

DocumentRoot is the location on your web server from which the web server will serve files if a user visits http://prestashop16.dev/. All of your web-visible files should be at or below that folder's level. The Directory block lets you specify Apache configuration rules that should only apply to a specific directory.


2 Answers

Ubuntu 13.10 uses apache 2.4, you should check all your apache configuration. But for this present case you should note that a2ensite and a2dissite commands won't be able to see your files in /etc/apache2/sites-available if it does not end with .conf, so rename it to sites-available/cnm.conf and run a2ensite cnm.

Then your Virtualhost definition is certainly better with *:80, it means this virtualhost is activated for all IP interfaces (*) on port 80. cnm.localhost or cnm are not valid values here, only IP numbers (Ip of your apache server) or * for all, and a port number.

Then check how you configuration is read by apache, running theses commands:

# load apache env
# be careful, there is a dot and a space
. /etc/apache2/envvars
# Check apache Virtualhosts config
apache2 -S

You should get something like:

VirtualHost configuration:
*:80                   is a NameVirtualHost
     default server something (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost something (/etc/apache2/sites-enabled/000-default.conf:1)
     port 80 namevhost cnm (/etc/apache2/sites-enabled/cnm.conf:4)

If it is ok, and if you have the right Ip in your hosts file for cnm, and you can test that with a ping, then using http://cnm/ should use the Virtualhost having cnm in the ServerName.

If you have an answer from the default Virtualhost then it means apache is not finding the name used in your Host header in the list of ServerName and ServerAlias available for that IP/port and fallbacks to the default Virtualhost. If you are really stuck (and you did not forgot to restart) you can always remove the default Virtualhost and keep only the one you are working on.

like image 188
regilero Avatar answered Oct 03 '22 14:10

regilero


I found the answer to my issue. I needed to delete the files in /etc/apache2/sites-enabled.

  1. Delete files in /etc/apache2/sites-enabled
  2. Rename config files in /etc/apache2/sites-available to have a .conf ending
  3. For each file in sites-available, run sudo a2ensite mysite.
  4. Run sudo service apache2 reload
like image 37
Tom Haws Avatar answered Oct 03 '22 14:10

Tom Haws