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

7

11

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.

Finecut answered 7/11, 2013 at 16:41 Comment(0)
F
5

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
Finecut answered 7/11, 2013 at 17:47 Comment(1)
I have the same problem and this didn't help. My vhosts are working, they just don't listen to the DocumentRoot setting.Detergency
L
12

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.

Lorrielorrimer answered 7/11, 2013 at 16:58 Comment(9)
Thanks! My Note 1 says that I already tried this, and it didn't help. I'm still seeing /var/www/index.html instead of /var/www/cnm/index.html :-)Finecut
I have the same problem and this didn't help. My vhosts are working, they just don't listen to the DocumentRoot setting. . /etc/apache2/envvars outputs nothing. Any idea?Detergency
@Detergency The dot command with envvars is there just to load the env variables of apache, so you can run apache2 -h and all others apache2 -X commands without configuration errors for missing env variables. Now there is no listen for a documentRoot, if you have a problem explain it with details on this site or serverfault.comLorrielorrimer
I mean listen like a dog listens when you give them a command. :P I already found the problem (See my answer below). Old vhosts are not compatible, apparently.Detergency
None of these is helping me, my DocumentRoot is not recognized after defining it in 000-default.conf file as seen from the output of apache2 -S. Any clues?Delaine
@engineer: make a new question, and add in this question the list of files present in /etc/apache2/sites/*, the output of apache2 -S, etc, details, details, details, the error is certainly in one of theses details, and we cannot guess where it is without informations.Lorrielorrimer
Here it is : #21136694Delaine
Also get in mind that they have changed the Access control directives (for example Order deny,allow Deny from all to Require all denied), see changes when upgrading from 2.2 to 2.4Vine
The combination of this answer and @PhoneixS' comment solved this for me.Seesaw
F
5

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
Finecut answered 7/11, 2013 at 17:47 Comment(1)
I have the same problem and this didn't help. My vhosts are working, they just don't listen to the DocumentRoot setting.Detergency
D
3

I couldn't find any step by step tutorial on how to make it work on my side. I gathered bits and pieces here and there, so for those who need all the steps to follow, here there are:

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/local-mydefault.conf

$ sudo gedit /etc/apache2/sites-available/local-mydefault.conf

Paste the following into the local-mydefault.conf file (Change the path '/your/full/path' to where you want to have your files. And change username to your own username):

# ------------------------------------------------------
<VirtualHost *:80>
    ServerName localhost
    ServerAdmin webmaster@localhost

    DocumentRoot /your/full/path
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /your/full/path>
            DirectoryIndex index.php
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Require all granted
            allow from all
    </Directory>

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

User username
Group username
# ------------------------------------------------------

Then type the following commands

$ cd /etc/apache2/sites-available/
$ sudo a2ensite local-mydefault.conf
$ sudo a2dissite 000-default.conf
$ sudo /etc/init.d/apache2 restart
Deodand answered 19/9, 2014 at 10:26 Comment(2)
Is the <Directory /> part required? Does not seem to do anything for me. But the other stuff solved my problem :) (I think you now need to specify all the options for your directory explicitly, but I am not sure)Paquette
@Paquette I'm not sure. My answer above is all the pieces I gathered through the research I did at that time to fix my issue. But I already forgot what all those pieces do exactly :-/Deodand
D
1

I found the answer to this issue:

When upgrading to Ubuntu 13.10, the DocumentRoot does not seem to make a difference.

This is because Apache 2.4 moved the Directory configuration somewhere else. Your old .conf files still have these lines:

    DocumentRoot "/var/www/myVhost"
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory "/var/www/myVhost">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

Remove (or comment out) the <Directory> directives so you only have:

    DocumentRoot "/var/www/myVhost"

Now reload your settings: service apache2 reload and DocumentRoot is back. :)

Detergency answered 19/11, 2013 at 15:51 Comment(2)
None of these is helping me, my DocumentRoot is not recognized after defining it in 000-default.conf file. Any clues?Delaine
No clue, it works here. Maybe add www-data as user:group?Detergency
C
0

Rename the file configuration "cnm" with the extension .conf

mv sites-available/cnm sites-available/cnm.conf
a2ensite sites-available/cnm.conf

And ready!

service apache2 reload
Crotty answered 31/1, 2014 at 22:20 Comment(0)
I
0

I have the same issue on way is to disable 000-default and reload apache ,but this isn't the solution becuase you must have just one vhost at a same time :(

sudo a2dissite 000-default.conf
sudo service apache2 reload
Imbecilic answered 29/7, 2014 at 22:42 Comment(0)
B
0

I ran into a similar issue. My server name and my FQDN were the same to the default was running into the /var/www/html directory. I disabled the default configuration and my site worked like a breeze. Thanks @regilero.

sudo a2dissite 000-default.conf

fixed it for me.

Brotherton answered 28/11, 2015 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.