2

After reading through various tutorials [1] I still can't get my VirtualHost settings to work as desired. I'm getting a 403 Forbidden when I try to use a VirtualHost with a directory below my user directory as its DocumentRoot.

What I've done so far

  • Created file /etc/apache2/sites-available/workspace with following content:

    NameVirtualHost *:80
    <VirtualHost *:80>
        ServerName project-site
        DocumentRoot /home/user/Workspace/project/site
    </VirtualHost>
    
  • Edited file /etc/hosts now yielding:

    127.0.0.1   localhost
    127.0.1.1   my-machine
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    
    # VirtualHosts added by me
    127.0.0.1   project-site
    
  • Enabled virtual hosts using sudo a2ensite workspace

  • Restarted Apache using sudo services apache2 restart
  • Tried opening http://project-site and http://project-site/test.html (where test.html is present in /home/user/Workspace/project/site/) in my webbrowser

What happens

  • Restarting Apache I get the following messages on the command line:

    * Restarting web server apache2
    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
    [Sun May 13 10:33:37 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
    [ OK ]
    
  • Opening either http://project-site or http://project-site/test.html a "403 Forbidden" is served.

What should happen

I'd like to have the contents of /home/user/Workspace/project/site being served when I browse to http://project-site.

What I learned so far

From reading similar questions on this site I learned that this is probably a permission problem [2]. Files in /home/user/Workspace/project/site might not be readable by www-data. But how do I know or correct this?

Furthermore .htaccess files were mentioned [3] being located in

/home/.htaccess
/home/user/.htacces
[...]
/home/user/path/to/project/.htaccess

and possibly not readable. I never created them, I don't want them, will I need them?

The second answer to another question [4] made me use NameVirtualHost responsible for the warning on restart of Apache. Is it necessary and if, how do I use it properly?

Any help is much appreciated! Tell me, if you need to know anything else to locate the problem.


Ressources

  1. http://www.thegeekstuff.com/2011/07/apache-virtual-host/, http://httpd.apache.org/docs/2.2/vhosts/name-based.html, http://mintarticles.com/read/software-articles/multiple-virtual-hosts-in-xampplampp-in-ubuntu,977/, http://www.pgorecki.pl/content/virtual-host-na-localho%C5%9Bcie-apache-ubuntu, ...
  2. Apache VirtualHost 403 Forbidden
  3. Ubuntu, Apache, virtualhost and Access forbidden
  4. VirtualHost configuration
Community
  • 1
  • 1
hielsnoppe
  • 2,819
  • 3
  • 31
  • 56

1 Answers1

1

I found the following solution, not satisfying me, but solving my primary problem. Indeed it is about permissions like suggested in [1]. My /home/user directory was not accessible to the webserver. In order to grant minimal possible permissions I used

chmod 701 /home/user

to make it accessible. Additionally I recursively gave group ownership to www-data for the webroot of the virtual host like recommended in [2], but I'm not sure, whether this is necessary.

sudo chown -R user:www-data /home/user/Workspace/project/site
sudo chmod -R g+s /home/user/Workspace/project/site

I'm going to ask for a more elegant solution in a separate question.

Regarding the other problems mentioned, I found out the following with the help of [3] besides other resources:

  • It is not necessary and may cause an error to have NameVirtualHost *:80 in the virtual hosts description, if it appears in one of apaches other configuration files.
  • To let apache know about its fully qualified domain name being localhost one creates a file /etc/apache2/conf.d/fqdn with content ServerName localhost.

  1. https://stackoverflow.com/a/7576526/948404
  2. https://stackoverflow.com/a/9133067/948404
  3. https://help.ubuntu.com/community/ApacheMySQLPHP
Community
  • 1
  • 1
hielsnoppe
  • 2,819
  • 3
  • 31
  • 56